Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Merge 1abf5fa into 4fdd74d
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisseau committed Oct 18, 2018
2 parents 4fdd74d + 1abf5fa commit 654104d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 7 additions & 11 deletions src/Cors/index.js
Expand Up @@ -272,20 +272,16 @@ class Cors {
._setExposeHeaders(response)

/**
* If request is not for OPTIONS call next. Otherwise set
* CORS headers.
* If request is OPTIONS set CORS headers before call next.
*/
if (request.method() !== 'OPTIONS') {
await next()
return
if (request.method() === 'OPTIONS') {
this
._setMethods(response)
._setHeaders(request.header('access-control-request-headers'), response)
._setMaxAge(response)
}

this
._setMethods(response)
._setHeaders(request.header('access-control-request-headers'), response)
._setMaxAge(response)

response.header('Content-length', 0).status(204).send('')
return next()
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/cors.spec.js
Expand Up @@ -353,10 +353,8 @@ test.group('Cors', () => {
{ key: 'Access-Control-Allow-Credentials', value: true },
{ key: 'Access-Control-Allow-Methods', value: 'GET,PUT,POST' },
{ key: 'Access-Control-Allow-Headers', value: 'Authorization' },
{ key: 'Access-Control-Max-Age', value: 90 },
{ key: 'Content-length', value: 0 }
{ key: 'Access-Control-Max-Age', value: 90 }
])
assert.equal(response._status, 204)
})

test('set vary header when options.origin is a string', async (assert) => {
Expand Down

0 comments on commit 654104d

Please sign in to comment.