mirror of
https://github.com/koajs/examples.git
synced 2026-01-18 14:38:19 +00:00
21 lines
409 B
JavaScript
21 lines
409 B
JavaScript
// rather than koa apps we can also use array
|
|
// bundles of middleware to the same effect.
|
|
|
|
function *responseTime(next) {
|
|
var start = new Date();
|
|
yield next;
|
|
var ms = new Date() - start;
|
|
this.set('X-Response-Time', ms + 'ms');
|
|
}
|
|
|
|
function *index(next) {
|
|
yield next;
|
|
if ('/' != this.url) return;
|
|
this.body = 'Howzit? From bar middleware bundle';
|
|
}
|
|
|
|
module.exports = [
|
|
responseTime,
|
|
index
|
|
];
|