var admin = require("firebase-admin");
var serviceAccount = require(__dirname+"/myserviceaccount.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://myproject.firebaseio.com"
});
db.ref('myref').on("child_changed", function(snapshot) {
...
});
的package.json
{
"name": "listener",
"version": "0.0.1",
"dependencies": {
"firebase-admin": "^5.2.1"
}
}
它工作正常,直到1-2小时后没有错误日志。任何人都可以解决这个问题吗?
答案 0 :(得分:0)
就我所见,您共享的代码不会启动任何云功能。我很惊讶它完全部署,但它肯定不会在Cloud Functions for Firebase中启动可靠的监听器。
要编写在云函数环境中正常运行的代码,请务必按照此处的说明进行操作:https://firebase.google.com/docs/functions/get-started。
具体来说:set up code in Cloud Functions that is triggered by updates to a database path的正确语法是:
exports.listenToMyRef = functions.database.ref('/myref/{pushId}')
.onUpdate(event => {
// Log the current value that was written.
console.log(event.data.val();
return true;
});