【发布时间】:2022-12-03 05:32:51
【问题描述】:
众所周知,您必须先测试您的函数,然后再将它们部署到 firebase 以避免循环和不需要的行为。我需要先运行一个本地环境来测试它,我该怎么做?
【问题讨论】:
标签: reactjs firebase google-cloud-firestore
众所周知,您必须先测试您的函数,然后再将它们部署到 firebase 以避免循环和不需要的行为。我需要先运行一个本地环境来测试它,我该怎么做?
【问题讨论】:
标签: reactjs firebase google-cloud-firestore
//How to Debug Firebase Functions locally
1 - 启动 EMU 进行调试功能(需要安装 Java) firebase 模拟器:启动 --inspect-functions
2 - 连接 Webstorm 调试器 编辑运行/调试配置 -> 附加到节点/Chrome(选择正确的端口(以防万一))(默认为 9229)
3 - 运行 ngrok 和服务器功能端口 (http://127.0.0.1:5001/sexybarbiegirl-f6068/us-central1/app) |这里 | ./ngrok http 127.0.0.1:5001
4 - 完成输出
|ngrok隧道| |您的其他 API 端点|
http://4386-2600-8801-192-4500-4dcd-e70f-e09f-63cb.ngrok.io/wherever-you-app-is/app
【讨论】:
要在本地运行 Firebase Firestore Cloud Functions 并调试它们,您可以使用 firebase emulators:start 命令,这将允许您在本地机器上测试您的函数,使用与生产环境相同的运行时和依赖项。
要调试您的函数,您可以使用 console.log 方法,并使用 Cloud Functions shell 中的 debug 命令将调试器附加到正在运行的函数。这将允许您单步执行代码、设置断点和检查变量,这可以帮助您识别和修复函数的任何问题。
$ firebase emulators:start
# Output
i emulators: Starting emulators: functions, firestore, hosting
i functions: Using Node.js version: 12
i functions: Emulator started at http://localhost:5001
i firestore: Emulator started at http://localhost:8080
i hosting: Emulator started at http://localhost:5000
$ firebase functions:shell
# In the Cloud Functions shell
> debug functions/helloWorld
# Output
[debug] functions:helloWorld: Listening on port 5001.
[debug] functions:helloWorld: Stopped the emulator.
【讨论】: