Firebase云端function总是超时

我正在探索Firebase云计算function,并试图通过http请求发送通知。

问题是,即使我设法发送通知,请求总是超时。

这是我的脚本

const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.friendRequestNotification = functions.https.onRequest((req, res) => { const senderId = req.query.senderId; const recipientId = req.query.recipientId; const getRecipientPromise = admin.database().ref(`/players/${recipientId}`).once('value'); const getSenderPromise = admin.database().ref(`/players/${senderId}`).once('value'); return Promise.all([getRecipientPromise, getSenderPromise]).then(results => { const recipient = results[0]; const sender = results[1]; const recipientToken = recipient.child("notificationsInfo/fcmToken").val(); const notificationAuthorization = recipient.child("notificationsInfo/wantsToReceiveNotifications").val(); const recipientBadge = recipient.child("notificationsInfo/badgeNumber").val(); const senderUsername = sender.child("username").val(); const payload = { notification: { title: `FriendRequest`, body: `You have a new friend request from ${senderUsername}!`, badge: (recipientBadge+1).toString() } }; if (notificationAuthorization) { return admin.messaging().sendToDevice(recipientToken, payload).then(response => { }); } return admin.database().ref(`/players/${recipientId}/notificationsInfo/badgeNumber`).setValue(recipientBadge+1); }); }); 

另外看来,从来没有更新的badgeNumber,是关系到超时问题?

HTTP触发的云function就像Express应用程序一样工作 – 您有一个响应对象( res ),您可以在请求完成时使用它来发送内容。 在这种情况下,它看起来像你可以做这样的事情:

 return Promise.all([ /* ... */ ]).then(() => { res.status(200).send('ok'); }).catch(err => { console.log(err.stack); res.status(500).send('error'); });