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); });