I am using expressJs 3.x and node 0.8.8. In my application I tried to catch all invalid urls. So I have added the following code. It is working fine, it is also catching the url, if I try to access the public or static files.
app.all('/*', function(req, res){
\\ Do some action like redirecting or whatever ...
});
How to avoid or pass static folder files (GET Request) and how to catch only invalid urls ?
Most likely, you’re calling
app.use(app.router)prior toapp.use(express.static(...)), so thatexpresstries to find matching route first, and only if there is no matched route it tries to find the corresponding static files.The configuration code should be like that:
so that
expresswill try to find a static file first.