客户端可调用Firebase功能部署到us-central1以外的其他区域时失败

Va5*_*li5 2 node.js firebase google-cloud-functions

客户端可调用Firebase函数失败,并显示“错误:由于格式不正确,无法读取数据。” 部署到us-central1以外的地区(尝试过欧洲西部和亚洲)。

服务器代码

exports.getName = functions.region('europe-west1').https.onCall((data, context) => {
     return { name: "Testopoulos" };
});
Run Code Online (Sandbox Code Playgroud)

客户端代码React Native Firebase

const httpsCallableUserName = firebase.functions().httpsCallable('getName');

getUserName = () => {
    httpsCallableUserName()
    .then(({ data }) => {
        console.log(data.name);
    })
    .catch(httpsError => {
        console.log(httpsError); 
    })
  }
Run Code Online (Sandbox Code Playgroud)

文档中有一条注释说:“ [使用HTTP函数提供动态内容进行托管时,您必须使用us-central1”,但我只是将一个对象返回到我们的前端React Native客户端,而不是使用Firebase Hosting。我阅读了有关该地区的其他文章,但我认为情况并非如此。有任何想法吗?

Ren*_*nec 8

根据文档, “客户还可以指定区域,如果函数在以外的任何区域中运行,则必须us-central1指定区域。”

如您所见(请参阅上面的注释),必须使用以下方法完成:

var functions = firebase.initializeApp(config).functions('europe-west1');
Run Code Online (Sandbox Code Playgroud)