samedi 3 janvier 2015

Route 404.html for Express app

I've seen plenty of posts tackling this issue but none seem to work for me and many solutions use deprecated methods.


I have static file directory already set up:



app.use(express.static(__dirname + "/public", {maxAge: 86400000*30 }));


Then I have a custom 404.html page in that public directory. Now, any incorrect URLs should be routed to that 404.html page. I've tried the following:



app.use(function(req, res, next){
res.render("404.html", { url: req.url });
});


But I get the response:



Error: Cannot find module 'html'


What am I doing wrong and why is such a simple thing so hard?


Aucun commentaire:

Enregistrer un commentaire