繁体   English   中英

如何在本地测试 firebase onCall()?

[英]how to test firebase onCall() locally?

我正在尝试使用 firebase 作为我的 android 应用程序的后端。 但是在这个早期阶段,部署到谷歌服务器并测试每个新功能和每个修复程序太慢了。

我想知道是否可以在本地运行它,以便我的 android 应用程序可以在 localhost:port 上调用 onCall() 函数?

我发现了一些 .useFunctionsEmulator(' http://localhost:8080 '); 但我不确定我需要什么导入以及如何启动本地“服务器”

当您使用firebase emulators:start Firebase Emulators 时,请检查日志消息以查看您的 Cloud Functions 在哪里运行,例如functions: Emulator started at http://localhost:5001 您可以使用firebase.functions().useFunctionsEmulator('http://localhost:5001')访问然后调用您的函数

如果您在真实设备上进行测试,则必须将 localhost 替换为您 PCIP 地址,假设 PC + 设备连接到同一网络。

如果您在Android Studio 的设备模拟器上进行测试,则必须将 localhost 替换为10.0.2.2 ,因为 localhost 会将模拟器指向其自己的本地主机地址,而不是您的 PC。

这对我有用。

我刚刚测试了它,我遇到了同样的问题,但没有找到解决方法,因为我猜我使用了过时的信息。

所以,我从我的 REACT 应用程序中做了什么

我在使用配置初始化 firebase 应用程序后添加了这一行:

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

我使用命令“firebase serve”来启动本地模拟过程。

请注意,5000 是默认端口,您可以通过添加 --port xxxx 来更改它,其中 xxxx 是端口号。

对于 Android,该功能显然在文档中,所以我想它也应该可以工作: https : //developers.google.com/android/reference/com/google/firebase/functions/FirebaseFunctions

那么如果您要在设备上进行测试,这意味着不是您的开发机器,那么它不会是本地主机,而是您机器的地址,或者您可以使用 ngrok 重定向端口并使用他们为您提供的临时链接。

您正在寻找:

  firebase.initializeApp(config);
  firebase.functions().useFunctionsEmulator('http://localhost:5001')

'http://localhost:5001'更改为您的模拟器设置为运行的任何内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM