我有一个最简单的谷歌onCall云功能:
// [START]
exports.echo = functions.https.onCall(async (data, context) => {
return {
value: "echo"
};
});
// [END]
我在谷歌云控制台测试中提交了以下内容:
{"data":"somedata"}
我得到以下错误:
{"error":{"message":"INTERNAL","status":"INTERNAL"}}
我所经过的物体似乎有问题。有人能告诉我正确的格式是什么吗?我在这里错过了什么?
附言:我最终试图通过Firebase/fire将onCall函数与客户端应用程序连接起来,但这也会产生同样的错误。
这是跟踪:
/workspace/node_modulesfirebase functions/lib/common/providers/https.js:349:16 at fixedLen(/workspace/ode_modules firebase functions/slib/providers/https.js:66:41(at/workspace/node_modulesFirebase functions/lib/common/providers/https.js:385:32 at processTicksAndRejections(internal/process/task_queues.js:95:5(未处理的错误类型错误:res.on不是位于新Promise的/workspace/node_modulesfirebase-functions/lib/common/providers/https.js:350:17处的函数((位于fixedLen的/workplace/node_modelesfirebase-fons/lib/providers/https:js:349:16处/processTicksAndRejections(internal/process/task_queues.js:95:5(上的workspace/node_modulesfirebase functions/lib/common/providers/https.js:385:32
这是index.ts:
import * as functions from "firebase-functions";
// The Firebase Admin SDK to access Cloud Firestore.
import admin = require("firebase-admin");
// Triggers
import { echo } from "./triggers/echo"
admin.initializeApp();
// Exports
module.exports = {
// OnCall
echo: functions.https.onCall(echo)
};
几件事:
- 箭头函数签名不正确
- 此同步响应不需要
async
- 上下文参数的正确类型为
CallableContext
:
import * as functions from 'firebase-functions';
export const echo = functions.https.onCall((data:any, context:functions.https.CallableContext) => ({
value: "echo"
}))