-
Notifications
You must be signed in to change notification settings - Fork 80
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
How to return dynamic origin? #52
Comments
The function should return a string. I'd also like to get some guidance on this function. What's the best practice? Say I have three domains I want to grant access to, "apple.example.com", "banana.example.com", and "cherry.example.com". I'm thinking something like this: const app = new Koa();
app.use(cors({
origin: (ctx) => {
const validDomains = [ 'apple.example.com', 'banana.example.com', 'cherry.example.com' ];
if (validDomains.indexOf(ctx.request.header.origin) !== -1) {
return ctx.request.header.origin;
}
return validDomains[0]; // we can't return void, so let's return one of the valid domains
},
}); Is this a good method? Is there a better way? |
Thank a lot! |
I believe you have to return the domain that was actually matched. |
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
String|Function(ctx)} origin
Access-Control-Allow-Origin
, default is request Origin headerwhat is
Function(ctx)
expect return value?I tried
origin:ctx=>ctx.request.origin
It doesn't work.
The text was updated successfully, but these errors were encountered: