0
votes

For firebase tools 6.9.2:

When using firebase emulators:start --only functions, hosting where the functions are invoked via a hosting rewrite rule, the functions are invoked with different request url path prefixes than if the functions were deployed to the cloud. For example given a firebase.json hosting snippet such as:

    {
      "target": "myapi",
      "public": "./dist/hosting/myapi",
      "rewrites": [{
          "source": "/api/myapi/*",
          "function": "myapi"
        }
      ]
    },

When deployed to firebase, the myapi function will be called with a request url that starts with: /api/myapi/

but if run in the emulator it ends up looking like: /[firebase-project-id]/[firebase-region]/myapi/api/myapi/

This doesn't make a difference if the function doesn't look at the request path but in my case, the function is a handler for an express (koa) handler with routes so knowing the base path is important.

I've looked to see if anything is available in process.env but only the GCLOUD_PROJECT name and a few FIREBASE_CONFIG params are there.

I could not find any documentation on more advanced control of the rewrite to a function in firebase.json.

I can work around it in testing by setting an environment variable to match the prefix the functions are running at locally and taking it into account during request handling. Unfortunately the request url prefix is not available until after the emulators are started and the function urls are logged.

I am hoping to find a better solution for testing.

1
If you would like to file a bug report or feature request with the Firebase CLI emulators, please post over at its GitHub. github.com/firebase/firebase-toolsDoug Stevenson
Thanks Doug. I filed an issue: github.com/firebase/firebase-tools/issues/1279tmcf

1 Answers

0
votes

This turned out to be a bug and is was resolved for my case in firebase-tools 6.10.0.

https://github.com/firebase/firebase-tools/issues/1279

This related issue was also opened:

https://github.com/firebase/firebase-tools/issues/1312