From 59617012f5db431e6adc6c36f2d5ffae2eeb0a28 Mon Sep 17 00:00:00 2001 From: Hans Kristian Flaatten <hans.kristian.flaatten@dnt.no> Date: Thu, 2 Jun 2016 15:36:15 +0200 Subject: [PATCH] feat(server): simplify not found route handling --- index.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8a5b865..923d423 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ const express = require('express'); const compression = require('compression'); const responseTime = require('response-time'); const corsHeaders = require('@starefossen/express-cors'); +const HttpError = require('@starefossen/http-error'); const app = module.exports = express(); const pg = require('./lib/pg'); @@ -26,9 +27,6 @@ app.use(compression()); app.use(responseTime()); app.use(corsHeaders.middleware); -app.use((req, res, next) => { - next(); -}); app.all('/CloudHealthCheck', (req, res) => { res.status(200); @@ -42,12 +40,7 @@ app.all('/CloudHealthCheck', (req, res) => { }); app.use('/api/v1', require('./controllers/n50')); - -app.use((req, res) => { - res.status(404).json({ - message: 'Not Found', - }); -}); +app.use((req, res, next) => next(new HttpError('Not Found', 404))); app.use(raven.middleware.express.requestHandler(sentry)); app.use(raven.middleware.express.errorHandler(sentry));