cors icon indicating copy to clipboard operation
cors copied to clipboard

Array - set origin -Not working

Open Naveenvuedata opened this issue 3 years ago • 3 comments

Trying to use Array - set origin to an array of valid origins from subdomains , but it is not working

Example:

  • http://test.example.com used CORS npm /.example2.com$/ NOT WORKING

Naveenvuedata avatar Dec 12 '22 10:12 Naveenvuedata

Trying to use Array - set origin to an array of valid origins from subdomains , but it is not working

Example:

  • http://test.example.com used CORS npm /.example2.com$/ NOT WORKING

Your regex targets example2.com. This will not work when your domain is example.com. You need to change the domain you are performing the request from to match the regex.

FredrikOseberg avatar Dec 14 '22 12:12 FredrikOseberg

Trying to use Array - set origin to an array of valid origins from subdomains , but it is not working Example:

  • http://test.example.com used CORS npm /.example2.com$/ NOT WORKING

Your regex targets example2.com. This will not work when your domain is example.com. You need to change the domain you are performing the request from to match the regex.

Yes, try to Implement the same way that you are saying by trying to add example.com in the regex /.example.com$/

But still not working

Expected: CORS should allow all subdomains (sub1.example.com , sub2.example.com) under the main domain example.com

If you have done pls share me piece of code for my understanding

Naveenvuedata avatar Dec 14 '22 12:12 Naveenvuedata

When using an Array or Regex, the header will appear only when there is an allowed match with the request's Origin header:

https://github.com/expressjs/cors/blob/master/lib/index.js#L58

enov avatar Jul 26 '23 16:07 enov