http-proxy-middleware
http-proxy-middleware copied to clipboard
Wrong origin, with CORS error in browser but response is 200 with right body
Expected behavior
We do a request from browser localhost:8100 to http://localhost:3000/proxy/tun0/blabla which should be redirected to https://tun0.bla.bla.com/bla
The strange thing I use several routes and any other is working expecting this one, and it is totally configured equals as the others.
The other strange thing is, the request is the only one request which has not 'localhost:8100' as Access-Control-Allow-Origin, but it has https://tun0.bla.bla.com, but in the response is OK 200 and has the response in it. But at the end I get a CORS error on the browser!!! This is very very stranged, some ideas
Actual behavior
Setup
- http-proxy-middleware: 0.17.4
- server: express 4.15.4
- cors 2.8.4
proxy middleware configuration
/* STUN */
var proxyMiddlewareStun0 = proxy({
target: 'https://tun0.bla.bla.com/bla',
changeOrigin: true,
headers: {
Origin: 'https://tun0.bla.bla.com'
},
cookieDomainRewrite: '',
pathRewrite: {
'/proxy/tun0': ''
},
logLevel: 'debug'
});```
#### server mounting
```javascript
var app = express();
app.use(cors(
{
credentials: true,
origin: function (origin, callback) {
callback(null, true)
}
}
)
);
app.use('/proxy/tun0', proxyMiddlewareStun0);
console.log("listening on port 3000");
var server = app.listen(3000);
hello, do you fix this issure?
hello,What did you do about it?
Not sure about the impact but this works for me.
onProxyRes: async (proxyRes: http.IncomingMessage) => {
proxyRes.headers['access-control-allow-origin'] = '[ORIGIN HERE]';
}
Not sure about the impact but this works for me.
onProxyRes: async (proxyRes: http.IncomingMessage) => { proxyRes.headers['access-control-allow-origin'] = '[ORIGIN HERE]'; }
This work for me. Thanks.