【发布时间】:2019-01-17 05:11:39
【问题描述】:
客户端可调用 Firebase 函数失败并显示“错误:无法读取数据,因为它的格式不正确。”当部署到 us-central1 以外的地区时(尝试过欧洲西部和亚洲)。
服务器代码
exports.getName = functions.region('europe-west1').https.onCall((data, context) => {
return { name: "Testopoulos" };
});
客户代码 (React Native Firebase)
const httpsCallableUserName = firebase.functions().httpsCallable('getName');
getUserName = () => {
httpsCallableUserName()
.then(({ data }) => {
console.log(data.name);
})
.catch(httpsError => {
console.log(httpsError);
})
}
docs 中有一条注释说“[当] 使用 HTTP 函数为托管提供动态内容时,您必须使用 us-central1”但我只是将一个对象返回给我们的前端 React Native 客户端而不是使用 Firebase 托管。我阅读了有关该地区的其他帖子,但我认为情况并非如此。有什么想法吗?
【问题讨论】:
-
请编辑问题以显示客户端代码。
-
感谢@DougStevenson 的评论我已经添加了客户端代码。
-
尝试
return { data : { name : "Testopulous" } };以确保返回值在发送到客户端时被正确包装。 -
@JamesPoag 结果相同。无论如何,如果它成功了,那就太奇怪了,因为它对我们只有 {name: "value"} 的 us-central1 工作得很好。
-
@RenaudTarnec 感谢您指出这一点!这听起来很有希望,但遵循该文档似乎并不像
var functions = firebase.functions('europe-west1');返回Firebase: firebase.functions() takes either no argument or a Firebase App instance. (app/invalid-app-argument).那样工作。
标签: node.js firebase google-cloud-functions