firebase - 如何在本地测试 `functions.https.onCall` firebase云功能?

标签 firebase google-cloud-functions

我似乎无法在 Firebase Documentation 中找到此问题的解决方案.

我想在本地测试我的 functions.https.onCall 函数。是否可以使用 shell 或以某种方式将我的客户端(启用了 firebase SDK)连接到本地服务器?

我希望避免每次都为了测试 onCall 函数的更改而进行部署。

<小时/>

我的代码

功能:

exports.myFunction = functions.https.onCall((data, context) => {
  // Do something
});

客户:

const message = { message: 'Hello.' };

firebase.functions().httpsCallable('myFunction')(message)
  .then(result => {
    // Do something //
  })
  .catch(error => {
    // Error handler //
  });

最佳答案

对于本地,您必须调用(在 firebase.initializeApp 之后)

firebase.functions().useFunctionsEmulator('http://localhost:5000') 

关于firebase - 如何在本地测试 `functions.https.onCall` firebase云功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50884534/

相关文章:

rest - 使用 Firebase 3 创建 API

firebase - 了解Firebase和谷歌云功能的用途

firebase - 如何优化每次应用启动时的 Firestore 读取

typescript - 在 firebase 云函数中使用 typescript 的 firebase-admin

ios - 如何修复 Firebase SIGABRT 崩溃 iOS

android - 如何使用 Rails 进行 Firebase 身份验证?

javascript - 在 Firebase 中,如何使用单独的 ORDER BY 执行 WHERE 查询

javascript - 如何在 firebase 函数环境中解决 CORS?

firebase - 如何在读取事件上触发firebase云功能

firebase - 带有通配符路径的 Firestore 云功能触发器