Answers for "how to replace cannot get with 404 error"

0

how to replace cannot get with 404 error

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');
});
Posted by: Guest on May-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language