nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Support firebase regions

Open pi0 opened this issue 2 years ago • 1 comments

https://github.com/nuxt/framework/issues/3126

https://firebase.google.com/docs/functions/manage-functions#modify-region

pi0 avatar Apr 12 '22 17:04 pi0

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)

okydk avatar Aug 29 '22 10:08 okydk

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));

luc122c avatar Nov 29 '22 10:11 luc122c

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.

luc122c avatar Feb 14 '23 23:02 luc122c

This might be related (recent release of firebase-tools): https://github.com/firebase/firebase-tools/pull/5504

davidstackio avatar Feb 24 '23 20:02 davidstackio

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

luc122c avatar Feb 24 '23 20:02 luc122c

@pi0 this will be resolved with the firebase v2 preset #1142.

In the meantime we can add @luc122c workaround to the documentation #1369

Hebilicious avatar Jul 01 '23 22:07 Hebilicious