express-http-proxy icon indicating copy to clipboard operation
express-http-proxy copied to clipboard

Change status response 405 to 200 to avoid CORS on OPTIONS method

Open itm-platform opened this issue 5 years ago • 5 comments

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

itm-platform avatar Dec 18 '19 07:12 itm-platform

same problem

joebnb avatar Mar 16 '20 10:03 joebnb

i think it caused by cors request,make sure your request in same origin,if your request wasn't a simple request

joebnb avatar Mar 16 '20 10:03 joebnb

same problem

in my case is other problem caused it, i was fixed that

joebnb avatar Mar 20 '20 01:03 joebnb

@joebnb how to fix it?

zry754331875 avatar Jun 22 '21 11:06 zry754331875

@joebnb how to fix it?

i was forget about cause,too long ago

joebnb avatar Jun 22 '21 11:06 joebnb