From b49593b13c2d7f50f9f8112db8c7ecd39486fbf1 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 25 Feb 2016 23:00:14 +0300 Subject: [PATCH] add not found route to the very end at development --- app.js | 16 ++++++++++++++++ lib/httpServer.js | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 78f6200..3ac9439 100644 --- a/app.js +++ b/app.js @@ -239,6 +239,22 @@ Steppy( app.notifier.init(app.config.notify, this.slot()); }, function() { + // only at development and only when there is no other request listeners + // (e.g. socketio) add not found route to the very end (after all + // plugins register) + if ( + env === 'development' && + app.httpServer._events && + _(app.httpServer._events.request).isFunction() + ) { + app.httpServer.addRequestListener(function(req, res, next) { + if (!res.headersSent) { + res.statusCode = 404; + res.end(req.method.toUpperCase() + ' ' + req.url + ' Not Found'); + } + }); + } + // load projects after all plugins to provide ability for plugins to // handle `projectLoaded` event app.projects.loadAll(this.slot()); diff --git a/lib/httpServer.js b/lib/httpServer.js index 8872c86..26991d5 100644 --- a/lib/httpServer.js +++ b/lib/httpServer.js @@ -35,6 +35,5 @@ Server.prototype._processRequestListeners = function(req, res, index) { }; exports.create = function() { - return new Server; + return new Server(); }; -