对于使用 Firebase 模拟器和节点 JS / Express 的无服务器 REST API,本地 API 端点是什



我有一个使用NodeJS和Google Cloud Functions(Firebase(的无服务器REST API。它适用于生产。但不是本地测试。

该应用程序是按照以下教程创建的:https://dev.to/levivm/creating-a-serverless-rest-api-using-google-cloud-functions-firebasefirestore-in-10-min-37km

在本地启动 Firebase 模拟器时,API 端点似乎不起作用,并返回错误:

URL http://my_local_server:8080/api/v1/my_api_route.
Output: Cannot GET /api/v1/my_api_route

根网址返回:http://my_local_server:8080/

{"status":"alive"}

您知道可能导致此问题的原因吗?

$ firebase emulators:start --only functions
i emulators: Starting emulators: functions
✔ functions: Using node@10 from host.
✔ functions: Emulator started at 0.0.0.0:8080
i functions: Watching "/home/ubuntu/environment/Crew-IQ/functions" for Cloud Functions...
⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
✔ functions[webApi]: http function initialized (0.0.0.0:8080/crew-iq/us-central1/w...).
✔ All emulators started, it is now safe to connect.

对于该应用程序,端点将是

http://localhost:8080/crew-iq/us-central1/webApi/api/v1/my_api_route
└───┬───┘ └─┬┘ └──┬──┘ └────┬────┘ └──┬─┘└─────────┬────────┘
host     │     │         │         │            │
port   │         │         │            │
project ID     │         │            │
function region │            │
function name    │
your express app

最新更新