-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,32 +5,23 @@ | |
|
||
'use strict'; | ||
|
||
var defaults = { | ||
origin: '*', | ||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE' | ||
}; | ||
var vary = require('vary'), | ||
defaults = { | ||
origin: '*', | ||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE' | ||
}; | ||
|
||
function configureOrigin(options, req) { | ||
var origin = options.origin, header; | ||
var origin = options.origin; | ||
if (origin === true) { | ||
origin = req.headers.origin; | ||
} else if (!origin) { | ||
origin = '*'; | ||
} | ||
header = { | ||
return { | ||
key: 'Access-Control-Allow-Origin', | ||
value: origin | ||
}; | ||
if (origin !== '*') { | ||
return [ | ||
{ | ||
key: 'Vary', | ||
value: 'Origin' | ||
}, | ||
header | ||
]; | ||
} | ||
return header; | ||
} | ||
|
||
function configureMethods(options) { | ||
|
@@ -107,6 +98,7 @@ | |
return applyHeaders(header, res); | ||
} else if (header.value) { | ||
if (res.set) { | ||
// for Express 4+ | ||
res.set(header.key, header.value); | ||
} else { | ||
// for Express <4 | ||
|
@@ -115,6 +107,9 @@ | |
} | ||
} | ||
}); | ||
if (res.get('Origin') !== '*') { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
troygoode
Author
Member
|
||
vary(res, 'Origin'); | ||
} | ||
}; | ||
|
||
if (method === 'OPTIONS') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
{ | ||
"name": "cors" | ||
, "version": "2.5.0" | ||
, "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"] | ||
, "homepage": "https://github.com/troygoode/node-cors/" | ||
, "repository": { | ||
"type": "git" | ||
, "url": "git://github.com/troygoode/node-cors.git" | ||
} | ||
, "contributors": [ | ||
"name": "cors", | ||
"version": "2.5.1", | ||
"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"], | ||
"homepage": "https://github.com/troygoode/node-cors/", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/troygoode/node-cors.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Troy Goode" | ||
, "email": "troygoode@gmail.com" | ||
, "web": "https://github.com/troygoode/" | ||
"name": "Troy Goode", | ||
"email": "troygoode@gmail.com", | ||
"web": "https://github.com/troygoode/" | ||
} | ||
] | ||
, "licenses": [ | ||
], | ||
"licenses": [ | ||
{"type": "MIT", "url": "http://www.opensource.org/licenses/mit-license.php"} | ||
] | ||
, "bugs": {"url": "https://github.com/troygoode/node-cors/issues"} | ||
, "main": "./lib/index.js" | ||
, "engines": { | ||
"node": ">=0.10.0" | ||
} | ||
, "dependencies": {} | ||
, "devDependencies": { | ||
"basic-auth-connect": "^1" | ||
, "body-parser": "^1.4.3" | ||
, "express": "^4" | ||
, "lint": "^1.1.2" | ||
, "mocha": "^1.18.2" | ||
, "should": "^3.3.1" | ||
, "supertest": "^0.12.0" | ||
} | ||
, "scripts": { | ||
"test": "./node_modules/mocha/bin/mocha" | ||
, "lint": "./node_modules/lint/bin/node-lint lib test" | ||
], | ||
"bugs": {"url": "https://github.com/troygoode/node-cors/issues"}, | ||
"main": "./lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"dependencies": { | ||
"vary": "^1" | ||
}, | ||
"devDependencies": { | ||
"basic-auth-connect": "^1", | ||
"body-parser": "^1.4.3", | ||
"express": "^4", | ||
"lint": "^1.1.2", | ||
"mocha": "^1.18.2", | ||
"should": "^3.3.1", | ||
"supertest": "^0.12" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha", | ||
"lint": "./node_modules/lint/bin/node-lint lib test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gak! This one line broke the ability to use this middleware outside of express. (worked beautifully before!) :-(