From 091293855a5c0a6b0edadd38fa8c195fbee44e1d Mon Sep 17 00:00:00 2001 From: Ilkka Oksanen Date: Fri, 31 Jan 2014 17:39:59 +0100 Subject: [PATCH 1/2] Only keep looping matching routes if they yield next --- lib/router.js | 16 ++++++++++++++-- test/lib/router.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/router.js b/lib/router.js index b9e85a9..a4a7025 100644 --- a/lib/router.js +++ b/lib/router.js @@ -5,6 +5,7 @@ var debug = require('debug')('koa-router') , methods = require('methods') , parse = require('url').parse + , compose = require('koa-compose') , Resource = require('./resource') , Route = require('./route'); @@ -62,13 +63,24 @@ router.middleware = function() { return yield next; } + var matchingMiddlewares = []; + // Dispatch route middlewares for (var i=0, len=matches.length; i Date: Sat, 1 Feb 2014 15:38:21 +0100 Subject: [PATCH 2/2] Fix resource tests --- test/lib/resource.js | 8 ++++---- test/lib/router.js | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/lib/resource.js b/test/lib/resource.js index a806567..9844b47 100644 --- a/test/lib/resource.js +++ b/test/lib/resource.js @@ -69,14 +69,14 @@ describe('Resource', function() { should.exist(this.params); this.params.should.have.property('forum', '54'); this.params.should.have.property('thread', '12'); - this.status = 200; + this.status = 204; } }); forums.add(threads); threads.base.should.equal('/forums/:forum/threads'); request(http.createServer(app.callback())) .get('/forums/54/threads/12') - .expect(200) + .expect(204) .end(function(err, res) { if (err) return done(err); done(); @@ -89,12 +89,12 @@ describe('Resource', function() { app.use(router.middleware()); app.resource({ index: function *() { - this.status = 200; + this.status = 204; } }); request(http.createServer(app.callback())) .get('/') - .expect(200) + .expect(204) .end(function(err, res) { if (err) return done(err); done(); diff --git a/test/lib/router.js b/test/lib/router.js index 4b0f2d5..1a39414 100644 --- a/test/lib/router.js +++ b/test/lib/router.js @@ -69,7 +69,6 @@ describe('Router', function() { this.params.should.have.property('lastname', 'smith'); this.status = 204; counter++; - yield next; }); app.get('/:surname', function *(next) { @@ -77,8 +76,6 @@ describe('Router', function() { this.params.should.have.property('surname', 'smith'); this.status = 204; counter++; - - yield next; }); var server = http.createServer(app.callback()); request(server)