【问题标题】:What format should data sent to a Google Cloud Functions onCall request be in?发送到 Google Cloud Functions onCall 请求的数据应该采用什么格式?
【发布时间】:2022-01-15 13:08:39
【问题描述】:

我有最简单的谷歌onCall云功能:

// [START]
exports.echo = functions.https.onCall(async (data, context) => {
  return {
    value: "echo"
  };
});
// [END]

我在谷歌云控制台测试中提交以下内容:

{"data":"somedata"}

我收到以下错误:

{"error":{"message":"INTERNAL","status":"INTERNAL"}}

我传递的对象似乎有问题。谁能告诉我正确的格式是什么?我在这里错过了什么?

P.s:我最终试图通过 Firebase/fire 将 onCall 函数与客户端应用程序连接起来,但这也给出了同样的错误。


这是踪迹:

/workspace/node_modules/firebase-functions/lib/common/providers/https.js:349:16 at fixedLen (/workspace/node_modules/firebase-functions/lib/providers/https.js:66:41) at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:385:32 在 processTicksAndRejections (internal/process/task_queues.js:95:5) 未处理的错误 TypeError: res.on is not a function at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:350:17 at new Promise () at /workspace/node_modules/firebase-functions/lib /common/providers/https.js:349:16 at fixedLen (/workspace/node_modules/firebase-functions/lib/providers/https.js:66:41) at /workspace/node_modules/firebase-functions/lib/common/ provider/https.js:385:32 at processTicksAndRejections (internal/process/task_queues.js:95:5)


这是 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)
};

【问题讨论】:

  • 这段代码乍一看还不错。您确定消息来自此代码,而不是来自调用此 Cloud Function 的客户端吗?
  • 嗨弗兰克,(几年前在 Google 会议上遇到你)...我正在控制台中对此进行测试,以消除客户端的任何问题。

标签: node.js firebase google-cloud-functions angularfire


【解决方案1】:

一些事情:

  1. 箭头函数签名不正确。
  2. 此同步响应不需要async
  3. 上下文参数的正确类型是CallableContext
import * as functions from 'firebase-functions';

export const echo = functions.https.onCall((data:any, context:functions.https.CallableContext) => ({
    value: "echo"
}))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    相关资源
    最近更新 更多