Reputation: 297
I've deployed a next.js app to Google Cloud and am using Functions and Hosting.
I recently tried to move everything to northamerica-northeast1
region. I re-deployed all the functions placing .region("northamerica-northeast1")
at the start of all my Functions as shown here. This successfully updated the location of all my functions.
However, I also use a function to serve my next.js app:
const server = functions.https
.onRequest((request, response) => {
return app.prepare().then(() => handle(request, response));
});
And I re-write all URLs to this function:
"hosting": {
"target": "webapp",
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "nextjs-server"
}
]
},
This is all standard next.js on Google Cloud stuff and I've been doing it for 2+ years. However, when I moved the function to the new region using this:
const server = functions
.region("northamerica-northeast1")
.https
.onRequest((request, response) => {
return app.prepare().then(() => handle(request, response));
});
It appears the re-write no longer works. The function was updated, but when I visit the site, I get a 404. Then, when I move the function back to the default region (by removing the .region()) it works again fine.
I tried on 3 current projects, same thing.
Finally, I tried creating a brand-new, fresh project and deployed to the northamerica-northeast
region (as before) and pushed the functions live with the region code in it...so my project never was hosted anywhere except northamerica-northeast1
and it still failed. However, by removing the region, the re-writes start working fine again and I can see the site. This is even though the entire rest of the site is in the northamerica-northeast1
region and just this one server function moved to the default region.
I believe this is a bug in rewrites on google cloud? Or is there something I'm missing or some doc somewhere that says re-writes are unavailable in this region?
Upvotes: 0
Views: 668
Reputation: 47833
If you want to use Hosting and Cloud Functions together, the Functions be located in us-central1
.
Firebase Hosting supports Cloud Functions in us-central1 only.
Serve dynamic content and host microservices with Cloud Functions
Upvotes: 1