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.
Today we're excited to announce Firebase Hosting integration for Google Cloud’s new Cloud Run service. Cloud Run is a fully managed compute platform that enables developers to run stateless containers that are invocable via HTTP requests in a language and framework of their choosing.
To rewrite your Cloud Function link go to the /firebase.json file. In the rewrites array add this object before the existing one: Run firebase deploy --only hosting to send changes to the server.
Cloud Run is a fully managed compute platform that enables developers to run stateless containers that are invocable via HTTP requests in a language and framework of their choosing. Firebase Hosting integration lets you use this architecture as a backend for a web app or microservice in your Firebase project.
Enable the Cloud Run API in the Google APIs console: Open the Cloud Run API pagein the Google APIs console. When prompted, select your Firebase project. Click Enableon the Cloud Run API page. Install and initializethe Cloud SDK.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With