0
votes

I have created an express app which is working pretty fine but when I'm trying to host the web app using firebase cloud functions the url rewrites rules in firebase.json seems to be not working properly.

code snippet from index.js file under functions folder

exports.app = functions.https.onRequest(app);

here is the snippet from firebase.json file

  "rewrites": [
  {
    "source": "/**{,/**}",
    "function": "app"
  }

I have also tried

  "rewrites": [
  {
    "source": "**",
    "function": "app"
  }

but none of the is working. I want all my webapp's url request from "http://url/someroute" to get routed to "http://url.com/app/someroute"

Right now for now all of this to work I have to change my hyperlinks from "/someroute" to "/app/someroute"

2

2 Answers

1
votes
    "rewrites": [
  {
    "source": "**",
    "function": "app"
  }

this works perfectly fine..Just check if you have also selected firebase hosting along with functions or do firebase init hosting and then firebase init functions seperately and then delete index.html from the public directory.

0
votes

The problem is that you trying to redirect to a function, not a route, so if you want to actually change the route, you have to use destination instead of function, as follows:

"rewrites": [
{
  "source": "**",
  "destination": "/app/**"
}

Or something similar to that, here is a community post that explain that in a little more detail and also the rewrite documentation that might be able to help you further