Skip to content

Commit

Permalink
Simplified router.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsm committed Nov 30, 2014
1 parent 486b62d commit b3ac3b0
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 506 deletions.
28 changes: 16 additions & 12 deletions lib/plugin/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ module.exports = {
options = options || {};
router = new Router(options);
}
core.delegate(router, ['get', 'post', 'put', 'delete', 'head', 'mount', 'notFound']);
core.delegate(router, ['get', 'post', 'put', 'delete', 'head', 'notFound']);

return function (request, response, go) {
var matched = router.route(request.method, request.url, this, function (request, response) {
var notFound = options.notFound || function (request, response) {
var error = {
statusCode: 404,
message: 'Content not found: ' + request.url
};
this.error(error);
};
notFound.call(this, request, response);
go();
});
var matched = router.dispatch(request.method, request.url, this);
if (matched) {
go();
} else {
// Default 404 handler
var self = this;
(function (request, response) {
var notFound = options.notFound || function (request, response) {
var error = {
statusCode: 404,
message: 'Content not found: ' + request.url
};
self.error(error);
};
notFound.call(self, request, response);
go();
})(request, response);
}
};
}
Expand Down
Loading

0 comments on commit b3ac3b0

Please sign in to comment.