Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Firebase rewrites to route /api/** to function and everything else to single page app

I've seen other stack overflow answers for using Firebase rewrites to route /api/** to their Express app function.

I'm following those instructions, but also trying to host a single page app.

Combining the two doesn't seem to work as the API routes are getting mapped to my index.html file still.

These are my rewrites

"rewrites": [
  {
    "source": "/api/**",
    "function": "api"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]

Is this possible?

like image 617
leros Avatar asked Oct 17 '25 04:10

leros


1 Answers

To answer your question, i've managed to do it by excluding /api/ from the single page app rules.

"rewrites": [
  {
    "source": "/api/**",
    "function": "api"
  },
  {
    "source": "!/api/**",
    "destination": "/index.html"
  }
]

Here we say :

  • Everything that start with "/api/" goes to the function named "api"
  • Everything else goes to your single page app (index.html)
like image 78
Gerard Walace Avatar answered Oct 18 '25 22:10

Gerard Walace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!