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

标签 javascript firebase google-cloud-functions

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

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

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

最佳答案

当您启动 Firebase 模拟器时 firebase emulators:start 检查日志消息以查看您的 Cloud Functions 在哪里运行,例如功能:模拟器启动于 http://localhost:5001。 您可以使用 firebase.functions().useFunctionsEmulator('http://localhost:5001')

访问然后调用您的函数

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

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

这对我有用。

关于javascript - 如何在本地测试 firebase onCall()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53352821/

相关文章:

javascript - 调用柯里化(Currying)函数而不传递另一个参数

javascript - Firestore Cloud Function 按日期查询

javascript - Firebase 函数不返回 set-cookies header

node.js - Firebase:如何从 Android 和 iOS 验证 Google 登录 token ID

javascript - 通过复选框进行多重过滤 - 纯 JS

android - 我可以让Firebase使用用户名登录过程吗?

javascript - Firebase 存储错误 - 不是函数

ios - 使用 Firebase 和 Swift 上传图像 (iOS)

javascript - Firebase JS http 函数返回从 axios API GET 调用收到的错误响应

javascript - TypeError : this. props.match 在组件中未定义