Merge pull request #50 from gswalden/patch-1

don't run forEach on undefined
This commit is contained in:
William Blankenship 2017-11-16 22:13:58 -08:00 committed by GitHub
commit 1b0348dec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -36,10 +36,12 @@ var constants = require('./constants.js')
module.exports = function (options) {
assert.object(options, 'options')
assert.optionalArray(options.origins, 'options.origins')
options.origins.forEach(function (o) {
assert.ok(typeof o === 'string' || o instanceof RegExp, o +
if (options.origins) {
options.origins.forEach(function (o) {
assert.ok(typeof o === 'string' || o instanceof RegExp, o +
' is not a valid origin')
})
})
}
assert.optionalBool(options.credentials, 'options.credentials')
assert.optionalArrayOfString(options.allowHeaders, 'options.allowHeaders')
assert.optionalArrayOfString(options.exposeHeaders,

View file

@ -94,4 +94,10 @@ describe('CORS: simple / actual requests', function () {
.expect(200)
.end(done)
})
it('Does not throw if "origins" option left undefined', function () {
should.doesNotThrow(function createServer () {
test.corsServer({})
})
})
})