【问题标题】:firebase serve and debugging functions?firebase 服务和调试功能?
【发布时间】:2018-11-02 17:54:08
【问题描述】:

我跑了

firebase 服务 --only-functions

然后跑了

函数检查 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());
    });
  });

【问题讨论】:

  • 如果重新加载会杀死模拟器进程,可能不会。您需要附加到替换过程。
  • @DougStevenson 经过进一步调查,即使我在运行后运行 inspect addMessage 命令,使用 firebase serve 似乎也不允许我进行调试,我必须执行 firebase deploy addMessage --trigger-http 然后函数检查 addMessage 以进行调试。是否可以在本地运行 firebase serve 和调试 firebase 功能?
  • 不,后台功能不会在本地触发。不过,您可以调试 http 函数。
  • 好吧,我尝试了 firebase serve --only 函数并调试了我的 addMessage 函数,但是断点没有命中:-/
  • @tweetypi 我也有同样的问题。你找到解决方案了吗?

标签: javascript node.js firebase visual-studio-code google-cloud-functions


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    从 firebase-tools v7.11.0 开始,Firebase 模拟器现在支持使用 --inspect-functions 选项附加调试器。 This answer 展示了 WebStorm 特定的指令,可以很容易地适应其他调试器。

    【讨论】:

      猜你喜欢
      • 2022-07-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 2020-12-07
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多