Boreal
0
Q:

express 404

app.use(function(req, res, next){
  res.status(404);

  // respond with html page
  if (req.accepts('html')) {
    res.sendFile('index.html');
    return;
  }

  // respond with json
  if (req.accepts('json')) {
    res.send({
      status: 404,
      error: 'Not found'
    });
    return;
  }

  // default to plain-text. send()
  res.type('txt').send('404 - Not found');
});
0
app.use(function(req, res, next){
  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');
});
0
app.use(function (req, res, next) {
  res.status(404).send("Sorry can't find that!")
})
0

New to Communities?

Join the community