Comparing version 2.0.0 to 2.0.1
20
index.js
@@ -33,12 +33,18 @@ 'use strict'; | ||
const origin_header_value = request.headers && request.headers.originl; | ||
const has_origin_header = typeof origin_header_value === 'string'; | ||
let origin = null; | ||
if ( options.origin instanceof RegExp ) { | ||
origin = options.origin.test( request.headers && request.headers.origin ) ? request.headers.origin : null; | ||
if ( typeof options.origin === 'string' ) { | ||
origin = options.origin; | ||
} | ||
else if ( Array.isArray( options.origin ) ) { | ||
origin = options.origin.includes( request.headers && request.headers.origin ) ? request.headers.origin : null; | ||
else if ( has_origin_header ) { | ||
if ( options.origin instanceof RegExp ) { | ||
origin = options.origin.test( origin_header_value ) ? origin_header_value : null; | ||
} | ||
else if ( Array.isArray( options.origin ) ) { | ||
origin = options.origin.includes( origin_header_value ) ? origin_header_value : null; | ||
} | ||
} | ||
else if ( typeof options.origin === 'string' ) { | ||
origin = options.origin; | ||
} | ||
@@ -45,0 +51,0 @@ if ( origin !== null ) { |
{ | ||
"name": "corsable", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "lightweight CORS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
8350
133