Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Only matching GET and POST routes if a static file doesn't match?

Only matching GET and POST routes if a static file doesn't match?

Problem

I have this route: app.get('/:a/:b/:c', routes.get);

And this Static definition:

app.use('/test', express.static(__dirname + '/test')); 

Now, the problem arises when I try to access /test/a/b.js. Since it matches both paths, routes.get is triggered. How do I prevent this, and only route if a static resource file wouldn't be served otherwise?

Problem courtesy of: Stefan Kendall

Solution

Put app.use(express.static(__dirname + '/test')) before app.use(app.router).

Middleware runs in the order defined in .configure().

Solution courtesy of: Ricardo Tomasi

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Only matching GET and POST routes if a static file doesn't match?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×