Skip to content

Commit

Permalink
expressjs#33: fix bug that dropped support for non-Express apps in ex…
Browse files Browse the repository at this point in the history
  • Loading branch information
troygoode committed Nov 10, 2014
1 parent 165f35e commit fee800f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
};

function configureOrigin(options, req) {
var origin = options.origin;
if (origin === true) {
origin = req.headers.origin;
} else if (!origin) {
origin = '*';
if (!options.origin) {
return {
key: 'Access-Control-Allow-Origin',
value: '*'
};
} else {
return [
{
key: 'Access-Control-Allow-Origin',
value: options.origin === true ? req.headers.origin : options.origin
},
{
key: 'Vary',
value: 'Origin'
}
];
}
return {
key: 'Access-Control-Allow-Origin',
value: origin
};
}

function configureMethods(options) {
Expand Down Expand Up @@ -95,21 +102,14 @@
headers.forEach(function (header) {
if (header) {
if (Array.isArray(header)) {
return applyHeaders(header, res);
applyHeaders(header, res);
} else if (header.key === 'Vary' && header.value) {
vary(res, header.value);
} else if (header.value) {
if (res.set) {
// for Express 4+
res.set(header.key, header.value);
} else {
// for Express <4
res.setHeader(header.key, header.value);
}
res.setHeader(header.key, header.value);
}
}
});
if (res.get('Origin') !== '*') {
vary(res, 'Origin');
}
};

if (method === 'OPTIONS') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cors",
"version": "2.5.1",
"version": "2.5.2",
"author": "Troy Goode <troygoode@gmail.com> (https://github.com/troygoode/)",
"description": "middleware for dynamically or statically enabling CORS in express/connect applications",
"keywords": ["cors", "express", "connect", "middleware"],
Expand Down

0 comments on commit fee800f

Please sign in to comment.