currently I am creating an API Gateway and for that I started working with the http-proxy-middleware library.
However I have read from the docs that libraries which modify the request usually cause problems with http-proxy-middleware (e.g body parser).
I reckon that the Firebase Cloud Functions library does that as well.
Has somebody experienced the same?
For Example, a post request with body does not terminate until a timeout is triggered.
And I am pretty much sure, that the problem cause is the Firebase library, simply because whenever I comment it out, the post request works normally.
Asked
Active
Viewed 632 times
0

DavidGetter
- 349
- 3
- 12
-
It's described in the documentation: https://github.com/chimurai/http-proxy-middleware Firebase uses name-based virtual hosts; Basically they are reusing a single ip-address for multiple host names. The host header needs to be proxied correctly for name-based virtual hosts. Try setting `changeOrigin to true` I think it will fix the host header for you. proxy: { '/__': { target: 'https://my-app.firebaseapp.com', changeOrigin: true, secure: false // Without this, all requests fail } } – Priyashree Bhadra May 24 '22 at 08:34
-
1Hello, I have the changeOrigin property set to true on all my routes. I compared both the headers from the req object on 1. an express.js server without firebase cloud functions 2. an express.js server with firebase cloud functions and they were quite different. Anyway, what helped me was to us the onProxyReq property and restream the req – DavidGetter May 30 '22 at 06:38
-
That's great. If your issue is resolved with the changes you mentioned, please consider posting that solution as an answer here. This will help the larger community. – Priyashree Bhadra May 30 '22 at 06:50
1 Answers
1
I followed the second most voted answer from chimera here
The one where restream is created.

DavidGetter
- 349
- 3
- 12