Search code examples
firebasegoogle-cloud-functionsfirebase-cli

What is the local API endpoint, for a serverless REST API that uses the firebase emulator and node JS / Express?


I have a serverless REST API that uses NodeJS and Google Cloud Functions (Firebase). It works on production. But not locally for testing.

The app was created following the tutorial at: https://dev.to/levivm/creating-a-serverless-rest-api-using-google-cloud-functions-firebasefirestore-in-10-min-37km

When the firebase emulator is started locally the API endpoint seems not to work, and an error is returned:

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

The root url returns: http://my_local_server:8080/

{"status":"alive"}

Do you know what might cause the issue?

$ 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.

Solution

  • For that application, the endpoint would be

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