diff --git a/config/lib/express.js b/config/lib/express.js index 129e0fd4..535cc5cf 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 33a43664..d58861fc 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);