firebase服务和调试功能?

twe*_*ypi 5 javascript node.js firebase visual-studio-code google-cloud-functions

我跑了

firebase服务——仅功能

然后跑了

函数检查 addMessage

这样我就可以调试 addMessage 函数。然而调试并没有成功。

跑步

firebase部署addMessage --trigger-http firebase检查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());
    });
  });
Run Code Online (Sandbox Code Playgroud)

jim*_*ont 3

尝试: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\"}