Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support firebase regions #90

Closed
pi0 opened this issue Apr 12, 2022 · 6 comments · Fixed by #1500
Closed

Support firebase regions #90

pi0 opened this issue Apr 12, 2022 · 6 comments · Fixed by #1500
Assignees

Comments

@pi0
Copy link
Member

pi0 commented Apr 12, 2022

nuxt/nuxt#13341

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

@okydk
Copy link
Contributor

okydk commented Aug 29, 2022

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)

@luc122c
Copy link
Contributor

luc122c commented Nov 29, 2022

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
Copy link
Contributor

luc122c commented Feb 14, 2023

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.

@davidstackio
Copy link

This might be related (recent release of firebase-tools): firebase/firebase-tools#5504

@luc122c
Copy link
Contributor

luc122c commented Feb 24, 2023

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

@Hebilicious
Copy link
Member

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants