How to apply several middlewares to a route in Nickel?


#1

Hi,

I would like to know if there is a way in Nickel to apply more than one middleware to a route. Maybe something similar to the “logger_middleware.rs” example but applying only to one route because I suppose the method server.utilize(mw) applies “mw” to all server’s routes.

It would be the ExpressJS pattern:

app.get(’/path/to/something’, mw1, mw2, …, mwN, function(req, res) {

});

Thank you very much


#2

I do not believe this is possible at the moment. You are correct that server.utilize() applies the middleware to all the routes. The issue is that server.get() expects one, and only one, handler function/closure. Your best bet might be to write a single piece of middleware which composes a bunch of functions.