nitro
nitro copied to clipboard
Support firebase regions
https://github.com/nuxt/framework/issues/3126
https://firebase.google.com/docs/functions/manage-functions#modify-region
Hosting rewrites to other than us-central1
is now supported.
Since Firebase Tools v11.4.0
https://github.com/firebase/firebase-tools/releases/tag/v11.4.0
Injection the region post build seems to work, so including it in the build step should be straight forward.
const server = functions.region('europe-west3').https.onRequest(nitroApp.h3App.nodeHandler)
Hi! I'd also be very interested in this to improve performance. I've tested modifying the server after build but before deployment this and it seems to work well:
-const server = functions.https.onRequest(toNodeListener(nitroApp.h3App));
+const server = functions.region("europe-west2").https.onRequest(toNodeListener(nitroApp.h3App));
Hi, I've been using the following configuration to workaround this. It uses the replace config to inject the region.
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
/* Other config options */
nitro: {
preset: "firebase",
replace: {
"functions.https.onRequest": "functions.region('europe-west2').https.onRequest",
},
},
});
I'd be happy to open a PR to tackle this, however I'm not sure where the best place is to store the configuration. Looking at the Firebase docs, there is no way to set the region with .firebaserc
or firebase.json
, only in the export itself. The nitro configuration reference doesn't seem to have any 'build options' key to store a region in. If a maintainer could suggest somewhere, I'd be happy to have a go at working it into the entry.
This might be related (recent release of firebase-tools): https://github.com/firebase/firebase-tools/pull/5504
Interesting, I see they have also updated their documentation: Direct requests to a function
Note: if region is omitted from the hosting config, the Firebase CLI will attempt to automatically detect the region from the function's source code which, if unspecified, defaults to us-central1. If the source code is unavailable, the CLI will attempt to detect the region from the deployed function. If the function is in multiple regions, the CLI will require region to be specified in the hosting config.
So the workaround above will still work, as the region will be detected from the code. More details can be found here: Integrate web frameworks with Hosting
@pi0 this will be resolved with the firebase v2 preset #1142.
In the meantime we can add @luc122c workaround to the documentation #1369