node.js - 客户端可调用 Firebase 函数在部署到 us-central1 以外的区域时失败

标签 node.js firebase google-cloud-functions

客户端可调用 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/

相关文章:

typescript - 传递 typescript 类方法作为回调

javascript - firebase 中无法提供数据 - 错误 : FIREBASE FATAL ERROR: Cannot parse Firebase url. 请使用 https ://<YOUR FIREBASE>. firebaseio.com

javascript - 与 insertOne 函数一起使用时,MongoDB 架构不插入属性

node.js - 如何通过 Node.js MongoDB Driver API 将 x.509 证书主题作为用户添加到 Mongodb 3.4?

java - Kotlin Firebase 反序列化

Firebase.Database.FirebaseException : Exception occured while processing the request

javascript - 如何使用 firebase 函数创建 api

Node.js typescript Azure 函数 : Cannot import with absolute path ( minimal reproducible example attached)

javascript - 查询字符串的正则表达式

javascript - Firebase 向用户发送电子邮件验证