客户端可调用Firebase功能部署到us-central1以外的其他区域时失败 [英] Client Callable Firebase Function fails when deployed to regions other than us-central1
问题描述
客户端可调用Firebase函数失败,并显示错误:由于格式不正确,无法读取数据."部署到us-central1以外的地区(尝试过欧洲西部和亚洲).
Client Callable Firebase Function fails with "Error: The data couldn’t be read because it isn’t in the correct format." when deployed to regions other than us-central1 (tried Europe West and Asia).
服务器代码
exports.getName = functions.region('europe-west1').https.onCall((data, context) => {
return { name: "Testopoulos" };
});
客户端代码(反应本机Firebase )
const httpsCallableUserName = firebase.functions().httpsCallable('getName');
getUserName = () => {
httpsCallableUserName()
.then(({ data }) => {
console.log(data.name);
})
.catch(httpsError => {
console.log(httpsError);
})
}
docs 中有一条注释,说"[[when]使用HTTP函数提供动态内容进行托管,您必须使用us-central1,但我只是将一个对象返回到我们的前端React Native客户端,而不使用Firebase托管.我阅读了有关该地区的其他文章,但我认为情况并非如此.有什么想法吗?
There is a note in the docs saying that "[when] using HTTP functions to serve dynamic content for hosting, you must use us-central1" but I am just returning an object to our frontend React Native client and not using Firebase Hosting. I read other posts about the regions but I don't think it is the same case. Any ideas?
推荐答案
根据文档客户端还可以指定区域,如果功能在us-central1
以外的任何区域中运行,也必须这样做."
According to the documentation "the client can also specify a region, and must do so if the function runs in any region other than us-central1
.".
如您所见(请参见上面的注释),必须使用以下方法完成:
As you have found (see comments above), it has to be done with:
var functions = firebase.initializeApp(config).functions('europe-west1');
这篇关于客户端可调用Firebase功能部署到us-central1以外的其他区域时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!