Search code examples
angularfirebaseproxyfirebase-hosting

Make proxy configuration works with firebase hosting


I have an angular app with some proxy configuration.

proxy.conf.js

  {
    "/my-api": {
      "target": "http://app.myapp.fr",
      "secure": false,
      "changeOrigin": true,
      "pathRewrite": {"^/my-api" : "api"}
    }
  }

I host my app with firebase hosting. According to firebase doc, I configured firebase.json this way:

"rewrites": [
    {
      "source": "/my-api/:request*",
      "destination": "http://app.myapp.fr/api/:request",
      "type": 301
    }
  ]

but I ended up with a 404, it seems like the redirect is not working...


Solution

  • According to the docs, that's not possible. You can only proxy to specific functions.

    You'll need to put an express server inside this one with a proxy: https://www.npmjs.com/package/http-proxy-middleware