Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow 'options.origin' to be a regexp #42

Closed
zaggino opened this issue May 8, 2015 · 5 comments
Closed

allow 'options.origin' to be a regexp #42

zaggino opened this issue May 8, 2015 · 5 comments

Comments

@zaggino
Copy link

zaggino commented May 8, 2015

usage would be: options.origin = /^(.*\.)?github\.com$/ to allow cors from any subdomain of github.com

implementation probably something like

if (options.origin.test && options.origin.test(req.headers.origin)) value = req.headers.origin
else value = ''

https://github.com/troygoode/node-cors/blob/master/lib/index.js#L25

@etiktin
Copy link
Contributor

etiktin commented May 9, 2015

@zaggino that's a good idea.
Technically you can already use regex to test for a match by setting origin to a function, but I think that directly assigning a regex will make the code concise and easier to understand.

I suggest to also add an option to assign an array to origin to support an origin whitelist.

Supporting regex and array will mean that you hardly never need to use the function syntax (the only reason to use it will be for complex scenarios).

@troygoode, what do you think?

@troygoode
Copy link
Member

@zaggino @etiktin yes, I like the idea. there is an open pull request (#48) that I'll merge once a unit test that covers the functionality has been added

@troygoode
Copy link
Member

this has shipped to npm as 2.7.0

cc @zaggino @etiktin @alex94puchades

@wilfredjonathanjames
Copy link

Are we able to get this feature documented?

@erikbaxstrom
Copy link

Are we able to get this feature documented?

Since this issue comes up high in google search results and the actual documentation doesn't, yes. It was documented.
Configuration Options

@expressjs expressjs locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants