Skip to content

Commit

Permalink
Allow clients to read custom response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtworkAD authored and sgress454 committed Mar 20, 2015
1 parent 9b9837d commit 82b383f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/hooks/cors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function(sails) {
credentials: true,
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'content-type',
exposeHeaders: '',
securityLevel: 0,
}
},
Expand Down Expand Up @@ -180,6 +181,9 @@ module.exports = function(sails) {
// Determine whether or not to allow cookies to be passed cross-origin
res.set('Access-Control-Allow-Credentials', !_.isUndefined(routeCorsConfig.credentials) ? routeCorsConfig.credentials : sails.config.cors.credentials);

// This header lets a server whitelist headers that browsers are allowed to access
res.set('Access-Control-Expose-Headers', !_.isUndefined(routeCorsConfig.exposeHeaders) ? routeCorsConfig.exposeHeaders : sails.config.cors.exposeHeaders);

// Handle preflight requests
if (req.method == "OPTIONS") {
res.set('Access-Control-Allow-Methods', !_.isUndefined(routeCorsConfig.methods) ? routeCorsConfig.methods : sails.config.cors.methods);
Expand All @@ -204,6 +208,7 @@ module.exports = function(sails) {
res.set('Access-Control-Allow-Credentials', '');
res.set('Access-Control-Allow-Methods', '');
res.set('Access-Control-Allow-Headers', '');
res.set('Access-Control-Expose-Headers', '');
}

next();
Expand Down

0 comments on commit 82b383f

Please sign in to comment.