Reputation: 95
In the deploying middleware example, middleware is used with kraken like the following
// index.js
...
app.requestBeforeRoute = function requestBeforeRoute(server) {
server.use(millionsServed());
...
};
But this way, the middleware is applied for all routes in the app. Suppose I only want to apply it for a specific route like in express like this:
app.get('/user', helpers.ensureAuthenticated, userCtrl.index);
How can I do the same with kraken?
Upvotes: 1
Views: 1594
Reputation: 552
you can added in the controller, same way like the express does.
// controllers/index.js
module.exports = function (server) {
server.get('/', helpers.ensureAuthenticated, function (req, res) {
var model = { name: 'krakene' };
res.render('index', model);
});
};
Upvotes: 4
Reputation: 366
You'd take the same approach in kraken. You register routes in the familar, express way inside your controllers. As such, you can register route-specific middleware just the same.
Upvotes: 2