express-http-proxy
express-http-proxy copied to clipboard
Change status response 405 to 200 to avoid CORS on OPTIONS method
Hi there. I'm running in CORS 405 Method not allowed that I'm trying to bypass with this proxy. Can I change the 405 Response Status from the server with a 200 to the client? The API server is returning a 405 status on every OPTIONS preflight request (GET with token header or POST with any payload). I tried all these options
- I have tried changing Origin and Referrer to match the API server with proxyReqOptDecorator. Still get the 405
- I have tried adiding 'POST, GET, OPTIONS, PUT' both to access-control-request-method and allow request headers in proxyReqOptDecorator
- I have tried delete proxyReqOpts.headers['access-control-request-headers'] with proxyReqOptDecorator. Same 405
- I have tried userResHeaderDecorator: () => ({'Access-Control-Allow-Origin': '*'}), but because the status is already 405, it has no effect
- I have tried proxyErrorHandler, but it doesn't catch 405
- I have tried in proxyReqOptDecorator to change the method to GET when it is OPTIONS, but obviously the real request never gets through (it's a GET with a token header, but it can be anything)
My hope was userResDecorator, but it doesn't seem to be able to change the status (which I assume is in proxyRes), only the data (proxyResData).
There is a note: The other arguments (proxyRes, userReq, userRes) are passed by reference, so you can currently exploit this to modify either response's headers, for instance, but this is not a reliable interface. I expect to close this exploit in a future release, while providing an additional hook for mutating the userRes before sending
Any help would be truly appreciated
same problem
i think it caused by cors request,make sure your request in same origin,if your request wasn't a simple request
same problem
in my case is other problem caused it, i was fixed that
@joebnb how to fix it?
@joebnb how to fix it?
i was forget about cause,too long ago