Skip to content

Commit

Permalink
Fix setting "maxAge" option to 0
Browse files Browse the repository at this point in the history
closes #158
  • Loading branch information
tomarad authored and dougwilson committed Nov 4, 2018
1 parent cb91054 commit 01477dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
unreleased
==========

* Fix setting `maxAge` option to `0`

2.8.4 / 2017-07-12
==================

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -131,7 +131,7 @@
}

function configureMaxAge(options) {
var maxAge = options.maxAge && options.maxAge.toString();
var maxAge = (typeof options.maxAge === 'number' || options.maxAge) && options.maxAge.toString()
if (maxAge && maxAge.length) {
return {
key: 'Access-Control-Max-Age',
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Expand Up @@ -672,6 +672,24 @@
cors(options)(req, res, null);
});

it('includes maxAge when specified and equals to zero', function (done) {
// arrange
var req, res, options
options = {
maxAge: 0
}
req = fakeRequest('OPTIONS')
res = fakeResponse()
res.end = function () {
// assert
assert.equal(res.getHeader('Access-Control-Max-Age'), '0')
done()
}

// act
cors(options)(req, res, null)
});

it('does not includes maxAge unless specified', function (done) {
// arrange
var req, res, next;
Expand Down

0 comments on commit 01477dc

Please sign in to comment.