Reputation: 203
I am setting up a redirect(rewrite) with my firebase hosting so that I can call an api that is running from google cloud run here.
I have tried changing the rewrite string from "/api/**"
(should catch all things to page.com/api/** and send that to the function). deleted the index.html and swapped to "**"
to capture ALL paths including index. Nothing has worked so far.
My hosting firebase.json is setup like so, is there something wrong with this?
{
"hosting": {
"public": "dist/public",
"ignore": ["firebase.json", "**.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"run": {
"serviceId": "next-js-base-api",
"region": "us-central1"
}
}
]
}
}
I also tried with normal redirects to another page, this does not work, what determines when the firebase.json settings begin to propagate and work?
I tried running the hosting emulator and with a modified rewrite "source": "/api/**"
which had the following results. Navigating to /api returns non crash (doesn't redirect) with output in browser of cannot GET /api
navigating to api/wkapi (a sub directory that is caught by the api endpoint) returns an unexpected error
in the browser and
Error: Unable to find a matching rewriter for {"source":"/api/**","run":{"serviceId":"next-js-base-api","region":"us-central1"}}
in the console.
Upvotes: 12
Views: 3319
Reputation: 560
In my case, the cause for this was misspelling function
in the firebase.json file, i,e:
"rewrites": [
{
"source": "**",
"function": "ngssr" // I had spelled this as "functions" (extra s)
}
]
Upvotes: 0
Reputation: 21
If all the above answers don't help you, the fix that worked for me was:
After deleting the generated index.html file, it was able to run my cloud run containers with rewrites.
Upvotes: 2
Reputation: 1277
Actually, I ran this just now and, looking at the logs of the deployed cloud-run helloworld container, found that custom-domain/helloworld is actually mapping onto container-domain/helloworld instead of simply mapping to container-domain/. To fix this, I had to add an additional app.get rule to my original Node.js program:
app.get('/helloworld', (req, res) => {
And then calling custom-domain/helloworld worked.
Upvotes: 3
Reputation: 181
Make sure to update to the latest version of your Firebase CLI by running:
npm install -g firebase-tools@latest
This will enable you to rewrite to cloud run instances as you are trying to do.
Upvotes: 5