In Express è possibile impostare l'header corretto dello status di una richiesta HTTP servendo un template specifico.
La soluzione è usare il metodo .status()
prima del metodo .send()
:
// Le route principali
// 404
app.get('*', function(req, res) {
res.render('404', {title: 'Not Found'}, function(err, html) {
if(!err) {
res.status(404).send(html);
}
});
});