Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (26 sloc) 679 Bytes
layout description
default
Before, after and around

Before, after and around

The before, after and around methods can easily be replaced by middleware:

Old:

let start;
ctrl.before(function (req, res) {
  start = Date.now();
});
ctrl.after(function (req, res) {
  console.log('Request handled in ', (Date.now() - start), 'ms');
});

New:

router.use(function (req, res, next) {
  let start = Date.now();
  next();
  console.log('Request handled in ', (Date.now() - start), 'ms');
});

Note that unlike around middleware receives the next function as the third argument (the "opts" argument has no equivalent).

You can’t perform that action at this time.