mirror of
https://github.com/scratchfoundation/restify-cors-middleware.git
synced 2024-12-20 21:02:33 -05:00
commit
f6f14dd329
1 changed files with 5 additions and 5 deletions
|
@ -21,19 +21,19 @@ exports.handler = function(options) {
|
||||||
if (req.method !== 'OPTIONS') return next();
|
if (req.method !== 'OPTIONS') return next();
|
||||||
|
|
||||||
// 6.2.1 and 6.2.2
|
// 6.2.1 and 6.2.2
|
||||||
originHeader = req.headers['origin'];
|
var originHeader = req.headers['origin'];
|
||||||
if (origin.match(originHeader, options.origins) === false) return next();
|
if (origin.match(originHeader, options.origins) === false) return next();
|
||||||
|
|
||||||
// 6.2.3
|
// 6.2.3
|
||||||
requestedMethod = req.headers['access-control-request-method'];
|
var requestedMethod = req.headers['access-control-request-method'];
|
||||||
if (!requestedMethod) return next();
|
if (!requestedMethod) return next();
|
||||||
|
|
||||||
// 6.2.4
|
// 6.2.4
|
||||||
requestedHeaders = req.headers['access-control-request-headers'];
|
var requestedHeaders = req.headers['access-control-request-headers'];
|
||||||
requestedHeaders = requestedHeaders ? requestedHeaders.split(', ') : [];
|
requestedHeaders = requestedHeaders ? requestedHeaders.split(', ') : [];
|
||||||
|
|
||||||
allowedMethods = [requestedMethod, 'OPTIONS'];
|
var allowedMethods = [requestedMethod, 'OPTIONS'];
|
||||||
allowedHeaders = DEFAULT_ALLOW_HEADERS.concat(['x-requested-with'])
|
var allowedHeaders = DEFAULT_ALLOW_HEADERS.concat(['x-requested-with'])
|
||||||
.concat(options.allowHeaders);
|
.concat(options.allowHeaders);
|
||||||
|
|
||||||
res.once('header', function() {
|
res.once('header', function() {
|
||||||
|
|
Loading…
Reference in a new issue