Reputation: 142
I am using Firebase dynamic hosting and would like the home page on my website (https://website.com) to redirect to a cloud function while all other urls are directed to a React app.
I have tried this in Firebase.json. But it doesn't seem to work.
"rewrites": [
{ "source": "/", "function": "app"},
{ "source": "**", "function": "/index.html"}
]
Any ideas on what the problem is?
Upvotes: 1
Views: 545
Reputation: 333
When you hit your website home page, firebase always tries to find the "index.html" file in your public directory. If it is found, your rewrite "is not executed". To avoid this, remove your "index.html" file (or just rename it), and the first rewrite will start working.
About the second rewrite, if you are trying to return a file of your public directory, the key of that object needs to be "destination", instead of "function".
Let's say that you rename your "index.html" file to "myApp.html". Your firebase.json file would be:
"rewrites": [
{ "source": "/", "function": "app"},
{ "source": "**", "destination": "/myApp.html"}
]
Upvotes: 4