Skip to content

Commit

Permalink
nested routes should not match superior routes
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxin authored and jonathanong committed Oct 27, 2014
1 parent b26af78 commit ef000ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Router.prototype.dispatcher = function () {
var match = trie.match(this.request.path)
var node = match && match.node
// If no match, go to next middleware
if (!node) return yield* next
if (notMatch(node)) return yield* next

// If no HEAD middleware, default to GET.
var method = this.method
Expand All @@ -34,4 +34,11 @@ Router.prototype.dispatcher = function () {
}
}

function notMatch(node) {
if (!node) return true;
if (Object.keys(node.child).length) return true;

return false;
}

function* noop() {}
11 changes: 11 additions & 0 deletions test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ describe('404', function(){
.get('/asdf')
.expect(404, done)
})

it('should 404 when not matched', function (done) {
app
.get('/app/home', function* (next) {
this.status = 204;
})

request(server)
.get('/app')
.expect(404, done)
})
})

function* noop(next) {
Expand Down

0 comments on commit ef000ef

Please sign in to comment.