I have an express.js app set up like this:
app.use(express.static(__dirname + '/public'));
...
app.all('*', require('./routes/all'));
So when I try to load /stylesheets/style.css
, request is dispatched to the routes
. How do I make the app first try to use "static", and then - the catch-all route?
Express is a perfect choice for a server when it comes to creating and exposing APIs (e.g. REST API) to communicate as a client with your server application.
Order matters in middleware because middleware functions are executed in a sequence and you'd need to execute one before the other in order to utilize its functionality.
Middleware get executed in sequential order. Simply put the static middleware before the routing middleware.
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.use(app.router);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With