From 7e86efe5494d4c95eca89e457cfc414ca5ff4bc2 Mon Sep 17 00:00:00 2001 From: mgerb42 Date: Thu, 7 Apr 2016 10:22:04 -0500 Subject: [PATCH] fixed 404 page --- app.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index fccdfea..99e8edb 100644 --- a/app.js +++ b/app.js @@ -48,9 +48,25 @@ app.use('/upload', upload); // catch 404 and forward to error handler app.use(function(req, res, next) { - var err = new Error('Not Found'); - err.status = 404; - res.render('404'); + //var err = new Error('Not Found'); + //err.status = 404; + res.status(404); + + // respond with html page + if (req.accepts('html')) { + res.render('404', { url: req.url }); + return; + } + + // respond with json + if (req.accepts('json')) { + res.send({ error: 'Not found' }); + return; + } + + // default to plain-text. send() + res.type('txt').send('Not found'); + //next(err); });