jthegedus / svelte-adapter-firebase

SvelteKit adapter for Firebase Hosting rewrites to Cloud Functions for a Svelte SSR experience

Home Page:https://github.com/jthegedus/svelte-adapter-firebase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only works in the US?

junaga opened this issue · comments

Am i to understand correctly that this SvelteKit Adapter only works if you chose to deploy all your cloud functions to us-central1 ?

There was mostly a limitation to the Firebase hosting only working in the US region. Therefore, it makes little sense to have your cloud functions somewhere else.

It seems the Firebase team is switching to a new API to host the functions which would support hosting in other regions. It seems the feature will land soonish this summer.

I can already specify a region when writing functions, like described here: https://firebase.google.com/docs/functions/locations#best_practices_for_changing_region

Or are you referring to something else?

@bummzack Hi, sorry for being unclear,

I was talking about "rewrite"ing Firebase Hosting requests to Cloud Functions for Firebase.

Important: Firebase Hosting supports Cloud Functions in us-central1.

This setting is usually required when building a REST/GraphQL API. Without this, you can only call functions using the npm:firebase library, not with fetch directly. There is also the option to tinker with GCP Function settings, but that's rather ugly.

This limitation is currently being worked on.

The next big step for the Firebase Hosting team is to allow Cloud Functions to be deployed to these servers in Europe and Asia as well.

@junaga Ah I see, thanks for the heads-up

Closing this issue as the rewrite limitation to us-central1 is still present, when the new origin regions are supported by function re-writes I will update the docs here and the validation step of the adapter.

I think we should keep the issue open,

until the Firebase team has implemented this feature. The feature is a requirement for anyone outside us-central1. Without it, this adapter doesn't make much sense. Anyone capable enough to deploy his svelte stack with Cloud Run is not dependent on this adapter.

I reopened the issue if only as a reminder. Hopefully once Cloud Functions gen 2 start being generally available (as opposed to being a preview), this can be solved.

In any case, this isn't a limitation of the svelte-firebase-adapter, but of firebase.

This adapter already supported Cloud Run, though I removed the docs because Funcs v2 was coming. I am not sure if all the recent refactors still cover this functionality as a lot of code has been updated recently.

Functions v2 is supported. Funcs v2 uses Cloud Run under the covers, though I am not sure it allows regions outside us-central1 with Hosting re-writes yet.

The fact of (Only works in the US) is not a limitation of this adapter, and it is documented very clearly is why I closed this. There is no code changes associated with this and it is therefore just tracking an external service (Firebase), which seems pointless.

From the Firebase Blog:

Update August 2022: Cloud Functions for Firebase now supports Hosting's new global origins! As of version 11.4.0 of the Firebase CLI, you can set a region in your function code, and Hosting will automatically talk to that function from a global region. Learn more in the docs

I think I need to update some validation code which enforces a region for this feature to be utilised.

Official Docs: https://firebase.google.com/docs/hosting/full-config#rewrite-functions

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 order of resolution is:

  • region specified in source code: exports.webhookAsia = functions.region('asia-northeast1')
  • defaults to us-central1 if no region specified
  • if no source code available (not sure how this works), detect from deployed function by checking target Firebase environment
  • when defined in multiple regions (I cannot find this feature in public docs), must specify in firebase.json:hosting