客户端可调用 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 托管。我阅读了有关这些地区的其他帖子,但我认为情况不同。有什么想法吗?
最佳答案
根据documentation “客户端还可以指定区域,如果函数在 us-central1
以外的任何区域运行,则必须这样做。”。
正如您所发现的(见上面的评论),它必须通过以下方式完成:
var functions = firebase.initializeApp(config).functions('europe-west1');
关于node.js - 客户端可调用 Firebase 函数在部署到 us-central1 以外的区域时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51772057/