Skip to content

Commit

Permalink
expressjs#31: reproduction attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
troygoode committed Nov 1, 2014
1 parent 0aca42e commit aaa1a4e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/error-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/example-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand All @@ -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*/
Expand Down
60 changes: 60 additions & 0 deletions test/issue-31.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

}());

0 comments on commit aaa1a4e

Please sign in to comment.