-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
CORS support for multiple origins #483
Comments
This is my proposed solution to accommodate this feature in Hapi: // headers.js
exports.cors = function (response, request) {
if (request.server.settings.cors) {
// Set the origin
// * it's a hack for multiple origins for Cors
var origin = request.raw.req.headers.origin;
authorizedOrigins = request.server.settings.cors._origin,
requestOrigin = request.server.settings.cors._origin;
// Validate the origin's authority
if (authorizedOrigins.indexOf(origin) > -1) {
requestOrigin = origin;
}
response.header('Access-Control-Allow-Origin', requestOrigin);
response.header('Access-Control-Max-Age', request.server.settings.cors.maxAge);
response.header('Access-Control-Allow-Methods', request.server.settings.cors._methods);
response.header('Access-Control-Allow-Headers', request.server.settings.cors._headers);
if (request.server.settings.cors.credentials) {
response.header('Access-Control-Allow-Credentials', 'true');
}
}
}; |
Trying to understand the use case. You can define multiple origin values as shows in your code above. Is this an issue with browsers not understanding that part of the spec? Is this about narrowing down the response to just one origin (as long as it is in the list)? |
@hueniverse, Thanks for the response. It seems to be about narrowing down the response to just one origin as long as it's in the list. I have several internal apps that will need to access our api. I'd prefer to just use XHR to handle information creation and updating. Make sense? |
Sure. Thing. Will be included in the next release. |
Awesome, thanks! |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Because we have no access to the request object when setting up cors in the server configuration, I am unable to define multiple authorized origins.
If there's another way, can you please provide an example? Thanks so much!
The text was updated successfully, but these errors were encountered: