garmeeh / local-cors-proxy

Simple proxy to bypass CORS issues.
MIT License
328 stars 81 forks source link

Reflect origin #26

Open adroste opened 2 years ago

adroste commented 2 years ago

Certain requests require an explicit origin in the 'Access-Control-Allow-Origin' header. A wildcard like '*' is not allowed. Therefore, you should add the option or better change the default value to enable origin reflection in the cors package.

See here: https://expressjs.com/en/resources/middleware/cors.html#configuration-options

origin: Configures the Access-Control-Allow-Origin CORS header. Possible values:

  • Boolean - set origin to true to reflect the request origin, as defined by req.header('Origin'), or set it to false to disable CORS.

Example implementation

Remove the default ('*') in here: https://github.com/garmeeh/local-cors-proxy/blob/d315bc87155f085b813cbc1a7d9ecc44b426e3a4/bin/lcp.js#L15

and add the boolean true as fallback for an undefined value here: https://github.com/garmeeh/local-cors-proxy/blob/d315bc87155f085b813cbc1a7d9ecc44b426e3a4/lib/index.js#L9

like so:

proxy.options('*', cors({
  credentials: credentials, 
  origin: origin || true // true (boolean): enables origin reflection
}));