From 74273dabb3a2971777b4dc143ded848de8a3c441 Mon Sep 17 00:00:00 2001 From: dotch Date: Thu, 2 Apr 2015 03:30:55 +0200 Subject: [PATCH] return a 404 for not found api, module and lib routes --- config/lib/express.js | 7 ------- modules/core/server/routes/core.server.routes.js | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/config/lib/express.js b/config/lib/express.js index 2ad68145b2..c3f6b953d2 100644 --- a/config/lib/express.js +++ b/config/lib/express.js @@ -177,7 +177,6 @@ module.exports.initModulesServerRoutes = function (app) { * Configure error handling */ module.exports.initErrorRoutes = function (app) { - // Assume 'not found' in the error msgs is a 404. this is somewhat silly, but valid, you can do whatever you like, set properties, use instanceof etc. app.use(function (err, req, res, next) { // If the error object doesn't exists if (!err) return next(); @@ -188,12 +187,6 @@ module.exports.initErrorRoutes = function (app) { // Redirect to error page res.redirect('/server-error'); }); - - // Assume 404 since no middleware responded - app.use(function (req, res) { - // Redirect to not found page - res.redirect('/not-found'); - }); }; /** diff --git a/modules/core/server/routes/core.server.routes.js b/modules/core/server/routes/core.server.routes.js index 33a436641c..d58861fc91 100644 --- a/modules/core/server/routes/core.server.routes.js +++ b/modules/core/server/routes/core.server.routes.js @@ -6,7 +6,9 @@ module.exports = function(app) { // Define error pages app.route('/server-error').get(core.renderServerError); - app.route('/not-found').get(core.renderNotFound); + + // Return a 404 for all undefined api, module or lib routes + app.route('/:url(api|modules|lib)/*').get(core.renderNotFound); // Define application route app.route('/*').get(core.renderIndex);