Skip to content

Commit

Permalink
fix #66 #73; publish as 2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
troygoode committed Aug 23, 2016
1 parent 6568976 commit 5dae6d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ var express = require('express')
, app = express();

var corsOptions = {
origin: 'http://example.com'
origin: 'http://example.com',
optionsSucccessCode: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
};

app.get('/products/:id', cors(corsOptions), function(req, res, next){
Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
var defaults = {
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
preflightContinue: false
preflightContinue: false,
optionsSuccessStatus: 204
};

function isString(s) {
Expand Down Expand Up @@ -166,7 +167,7 @@
if (options.preflightContinue ) {
next();
} else {
res.statusCode = 204;
res.statusCode = options.optionsSuccessStatus || defaults.optionsSuccessStatus;
res.end();
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cors",
"version": "2.7.2",
"version": "2.8.0",
"author": "Troy Goode <troygoode@gmail.com> (https://github.com/troygoode/)",
"description": "middleware for dynamically or statically enabling CORS in express/connect applications",
"keywords": ["cors", "express", "connect", "middleware"],
Expand Down
20 changes: 20 additions & 0 deletions test/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@
cors()(req, res, next);
});

it('can configure preflight success response status code', function (done) {
// arrange
var req, res, next;
req = fakeRequest();
req.method = 'OPTIONS';
res = fakeResponse();
res.end = function () {
// assert
res.statusCode.should.equal(200);
done();
};
next = function () {
// assert
done('should not be called');
};

// act
cors({optionsSuccessStatus: 200})(req, res, next);
});

it('doesn\'t shortcircuit preflight requests with preflightContinue option', function (done) {
// arrange
var req, res, next;
Expand Down

0 comments on commit 5dae6d8

Please sign in to comment.