【发布时间】:2017-07-01 20:12:33
【问题描述】:
这是我第一次使用 Cloud Functions for Firebase 和 Node.js,所以
我不知道为什么我在 Firebase 控制台上看不到任何日志。
至少,我已经成功部署了下面的功能
'use strict';
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
/* Listens for new messages added to events and sends a notification to
subscribed users */
exports.pushNotification =
functions.database.ref('/events/{pushId}').onWrite( event => {
console.log('Push notification event triggered');
/* Grab the current value of what was written to the Realtime Database
*/
var valueObject = event.data.val();
/* Create a notification and data payload. They contain the
notification information, and message to be sent respectively */
const payload = {
data: {
eventType: valueObject.eventType,
receiver: valueObject.receiver,
requester: valueObject.requester
}
};
/* Create an options object that contains the time to live for the
notification and the priority. */
const options = {
priority: "high",
timeToLive: 60 * 60 * 24 //24 hours
};
return admin.messaging().sendToTopic(valueObject.receiver, payload,
options).then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
但是,即使我将一些数据写入“事件”数据库,我也无法在 Firebase 控制台上看到任何日志消息。 这是否意味着这个功能根本没有被触发?
如果有人能提出这个问题的原因,我将不胜感激。
【问题讨论】:
-
默认情况下,函数调用会记录在 Cloud Functions for Firebase 控制台中,即使您的代码中没有任何
console.log()语句也是如此。这不是发生在你身上吗? -
@FrankvanPuffelen 不,我看不到任何日志,但它说现在有 15 次处决。每当我再次部署该函数时,我都会额外执行 2 次。
-
你能找到我的代码关于这个问题的任何问题吗?
-
嗯...我不知道那里发生了什么。我总是看到登录console.firebase.google.com/u/0/project/_/functions/…
标签: android node.js firebase google-cloud-messaging firebase-cloud-messaging