从VS Code集成终端我运行firebase serve --only functions,hosting
然后在调试选项卡中我创建了默认的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想调试服务器端(functions/index.js)而不是客户端.
我从https://code.visualstudio.com/docs/nodejs/nodejs-debugging尝试了一些配置而没有运气.
如何在VS Code中调试Firebase功能?
debugging 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 …Run Code Online (Sandbox Code Playgroud) javascript node.js firebase visual-studio-code google-cloud-functions
看下面我的代码非常简单......它监听实时数据库中数据库字段的变化。
const functions = require("firebase-functions");
var admin = require("firebase-admin");
exports.onActiveUpdate = functions.database
.ref("/profiles/users/{userId}/active")
.onUpdate((change, context) => {
//code here
return true;
});
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下命令在本地调试代码
firebase serve --only functions
firebase serve
firebase emulators:start
Run Code Online (Sandbox Code Playgroud)
我总是收到同样的消息...
+ functions: Emulator started at http://localhost:5001
i functions: Watching "C:\code\rn\xs\fb_functions\functions" for Cloud Functions...
i functions[onActiveUpdate]: function ignored because the database emulator does not exist or is not running.
+ All emulators started, it is now safe to connect.
Run Code Online (Sandbox Code Playgroud)
但是当我转到 localhost:5001 时......我看到的只是一个{"status":"alive"}顶部带有 的空白页面。
这是正确的行为吗?谢谢
debugging firebase-realtime-database google-cloud-functions firebase-cli