首页 > 解决方案 > firebase 服务和调试功能?

问题描述

我跑了

firebase 服务 --only-functions

然后跑了

函数检查 addMessage

所以我可以调试 addMessage 函数。然而,调试并没有奏效。

跑步

firebase deploy addMessage --trigger-http firebase inspect addMessage

确实工作并允许我调试,但它似乎不支持热重载。

是否可以同时进行热重载和调试?

我的 index.js:

const functions = require('firebase-functions');

// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();

exports.addMessage = functions.https.onRequest((req, res) => {
    // Grab the text parameter.
    const original = "123";//req.query.text;
    // Push the new message into the Realtime Database using the Firebase Admin SDK.
    return admin.database().ref('/messages').push({original: original}).then((snapshot) => {
      // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
      return res.redirect(303, snapshot.ref.toString());
    });
  });

标签: javascriptnode.jsfirebasevisual-studio-codegoogle-cloud-functions

解决方案


尝试:ndb firebase serve

调试器断点被可见的堆栈跟踪命中,请注意它有点慢,所以给调试器时间来检测子进程

此外,我能够使用(删除值的上限)单独调试云函数:

GCLOUD_PROJECT=THE-FIREBASE-PROJECT node --inspect-brk /path/to/functions-framework --target FUNCTION-NAME --port=5000

其中 functions-framework 只是从 index.js 文件用于目标函数的工作目录扩展为已安装的 functions-framework (在我的情况下为全局)的完整路径。

或者,在需要 FIREBASE_CONFIG 的时间或地点尝试调整此格式以适应: FIREBASE_CONFIG="{\"databaseURL\":\"https://YOUR-FIREBASE-PROJECT.firebaseio.com\",\"storageBucket\":\"YOUR-FIREBASE-PROJECT.appspot.com\",\"projectId\":\"YOUR-FIREBASE-PROJECT\"}


推荐阅读