【问题标题】:Firebase: how to connect client SDK to cloud functions served locally?Firebase:如何将客户端 SDK 连接到本地提供的云功能?
【发布时间】:2019-03-04 01:30:18
【问题描述】:

我有一个使用 firebase web SDK 来初始化 firebase 的 react-native 移动应用:

import firebase from 'firebase';

firebase.initializeApp({
  apiKey: ...,
  authDomain: ...,
  projectId: ...,
  databaseURL: ...,
  hostingURL: ...,
  storageBucket: ...,
});

然后我可以像这样调用云函数:

firebase.functions().httpsCallable('someFunction')(params);

我的目标

我想要的是配置我的客户端以连接到我在命令行中执行 $ firebase serve 后正在运行的本地服务云功能:

✔  functions: inviteNonuserToCircle: http://localhost:5000/mvp-finli-remote-local/us-central1/inviteNonuserToCircle
✔  functions: inviteUserToCircle: http://localhost:5000/mvp-finli-remote-local/us-central1/inviteUserToCircle

我想这样做,以便我可以在本地快速测试和迭代我的函数,而无需部署它们。

附:我已经设法使用 Postman 使用 $ firebase serve 提供的 URL 测试本地运行功能,但我想直接使用我的客户端应用程序测试它们。

【问题讨论】:

    标签: firebase react-native google-cloud-functions


    【解决方案1】:

    如果您仍在寻找解决方案,客户端 SDK 已经有更新,这里是相关问题:Testing https.onCall with locally running serve

    简而言之,从 5.2.0 版开始,您可以使用 useFunctionsEmulator 函数为您的云函数选择不同的 URL。例如:

    const app = firebase.initializeApp({ ... });
    app.functions().useFunctionsEmulator('http://localhost:5000');
    

    【讨论】:

    猜你喜欢
    • 2020-10-02
    • 2018-06-10
    • 2016-09-13
    • 2020-01-22
    • 2018-09-06
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    相关资源
    最近更新 更多