【发布时间】:2019-01-31 13:01:39
【问题描述】:
按照官方 firebase 云函数教程 (https://firebase.google.com/docs/functions/get-started),尝试实际部署和使用函数时遇到错误 (https://firebase.google.com/docs/functions/get-started#deploy-and-execute-addmessage)。成功完成示例函数的部署并指示“在addMessage() URL中添加文本查询参数,并在浏览器中打开”,结果是文本
错误:无法处理请求
出现在浏览器中。在浏览器中检查开发者控制台,我看到了
加载资源失败:服务器响应状态为500()
(实际上不知道如何解释这一点)并查看 firebase 仪表板中的使用情况统计信息,可以看到该功能正在被激活(只是工作不顺利)。用于部署的确切代码如下所示
//import * as functions from 'firebase-functions';
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
// export const helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();
// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addMessage = functions.https.onRequest((req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
return admin.firestore().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());
});
});
以前从未使用过谷歌云功能,如果有任何调试信息或此处可能出错的解决方案,我们将不胜感激。
最终,希望最终使用云函数与 firestoreDB 一起使用,而官方教程似乎旨在与 firebaseDB 一起使用。因此,如果在这方面需要进行任何特定的更改,我们也将不胜感激。
【问题讨论】:
标签: firebase google-cloud-firestore google-cloud-functions