From aaa1a4ed102ab3c91fe6b5ff5a0a07733e276fff Mon Sep 17 00:00:00 2001 From: Troy Goode Date: Sat, 1 Nov 2014 12:11:31 -0700 Subject: [PATCH] #31: reproduction attempt --- test/error-response.js | 2 +- test/example-app.js | 4 +-- test/issue-31.js | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 test/issue-31.js diff --git a/test/error-response.js b/test/error-response.js index 10ed7bb..c900de2 100644 --- a/test/error-response.js +++ b/test/error-response.js @@ -37,7 +37,7 @@ /*jslint unparam: true*/ // `req` is part of the signature, but not used in these routes app.use(function (err, req, res, next) { if (err.message === '401') { - res.send(401, 'unauthorized'); + res.status(401).send('unauthorized'); } else { next(err); } diff --git a/test/example-app.js b/test/example-app.js index 2b49740..656c648 100644 --- a/test/example-app.js +++ b/test/example-app.js @@ -17,7 +17,7 @@ simpleApp = express(); /*jslint unparam: true*/ // `req` is part of the signature, but not used in these routes simpleApp.head('/', cors(), function (req, res) { - res.send(204); + res.status(204).send(); }); simpleApp.get('/', cors(), function (req, res) { res.send('Hello World (Get)'); @@ -32,7 +32,7 @@ complexApp = express(); complexApp.options('/', cors()); /*jslint unparam: true*/ // `req` is part of the signature, but not used in this route - complexApp.del('/', cors(), function (req, res) { + complexApp.delete('/', cors(), function (req, res) { res.send('Hello World (Delete)'); }); /*jslint unparam: false*/ diff --git a/test/issue-31.js b/test/issue-31.js new file mode 100644 index 0000000..351dd19 --- /dev/null +++ b/test/issue-31.js @@ -0,0 +1,60 @@ +/*jslint indent: 2*/ +/*global require: true, module: true, describe: true, it: true*/ + +(function () { + + 'use strict'; + + var should = require('should'), + express = require('express'), + supertest = require('supertest'), + cors = require('../lib'), + app, + mainRouter, + itemsRouter; + + /* -------------------------------------------------------------------------- */ + + itemsRouter = express.Router(); + itemsRouter.get('/', function (req, res) { + res.send('hello world'); + }); + + mainRouter = express.Router(); + mainRouter.use('/items', itemsRouter); + + app = express(); + app.use(cors()); + app.use(mainRouter); + + /* -------------------------------------------------------------------------- */ + + describe('issue #31', function () { + it('OPTIONS works', function (done) { + supertest(app) + .options('/items') + .expect(204) + .set('Origin', 'http://example.com') + .end(function (err, res) { + should.not.exist(err); + res.headers['access-control-allow-origin'].should.eql('*'); + done(); + }); + }); + + it('GET works', function (done) { + supertest(app) + .get('/items') + .expect(200) + .set('Origin', 'http://example.com') + .end(function (err, res) { + should.not.exist(err); + res.headers['access-control-allow-origin'].should.eql('*'); + res.text.should.eql('hello world'); + done(); + }); + }); + }); + +}()); +