Reputation: 747
I was following this guide https://medium.com/firebase-developers/hosting-flask-servers-on-firebase-from-scratch-c97cfb204579 and I'm stuck on firebase's ./node_modules/.bin/firebase serve
command
I was successfully able to deploy the project using Cloud Run and get a service url that is working for the site, but when I try and serve it locally it produces this error on the static page when running to localhost:5000:
A problem occurred while trying to handle a proxied rewrite: error looking up URL for Cloud Run service: FirebaseError: HTTP Error: 404, Resource 'flask-fire' of kind 'SERVICE' in region 'us-central1' in project 'cjcflaskapp10192021' does not exist.
Here is my firebase.json file.
{
"hosting": {
"public": "static",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [{
"source": "**",
"run": {
"serviceId": "flask-fire"
}
}]
}
}
Upvotes: 1
Views: 1103
Reputation: 11
The above answer from ErnestoC is correct.
I had the same issue and figured I had to choose e.g. europe-west3 as my region for the Flask API.
Thank you!
Upvotes: 0
Reputation: 2904
From the article comments I discovered several users who also experienced the same error, one comment in special refers to a region mismatch between Firebase Hosting and the Cloud Run service:
Looks like the region selection is an important step. Because in the first step, I deployed the server side code ( app.py ) in region us-west-1 and it worked fine. But after setting up the firebase deployment setup, it strangely looked up for my URL in region us-central1. Error Log : A problem occurred while trying to handle a proxied rewrite: error looking up URL for Cloud Run service: FirebaseError: HTTP Error: 404, Resource 'flask-simple-pwa' of kind 'SERVICE' in region 'us-central1' in project 'flask-simple-pwa' does not exist. When I checked the documentation for firebase, in Location us-west1 is nowhere to be seen . It could be that this has changed since the time you wrote the article. Is this something that you can verify?
There is an official documentation on how to serve dynamic content from Cloud Run to use with Firebase Hosting, which is more complete and it explains that a region should be set on firebase.json
that matches the region of your current Cloud Run deployment. If no region is set, FIrebase hosting will default to us-central1
.
"hosting": {
// ...
// Add the "rewrites" attribute within "hosting"
"rewrites": [{
"source": "/helloworld",
"run": {
"serviceId": "helloworld", // "service name" (from when you deployed the container image)
"region": "us-central1" // optional (if omitted, default is us-central1)
}
}]
}
If this does not match with your Cloud Run deployment, it can cause this error. For a list of supported locations for Firebase, you can refer to this page.
Upvotes: 1