Tuesday, 2 May 2017

Express js, how to match all routes, even sub routes

I am building a node js app that needs to return a 404 page for all routes except for the /video route.

app.get('/video/*', Video.show)
app.get('*', (req,res) => res.render('not_found'))

This works if the URL does not have subdirectories. The problem arises when someone enters a URL with subdirectories such as /hello/subhello/. This is not caught by my routes.

I already tried this with no success:

app.get('/*', (req,res) => res.render('not_found'))

Am I missing something ?

Thanks



via Nicola Pedretti

No comments:

Post a Comment