examples/vhost/apps/array.js
dongyu 50bcadf73e migrate to koa@2 (#108)
* support async/await

* change nodejs version 4 or 6 to 5.6

* eslint

* remove jade
2017-05-30 20:44:57 +08:00

21 lines
434 B
JavaScript

// rather than koa apps we can also use array
// bundles of middleware to the same effect.
async function responseTime(ctx, next) {
const start = new Date();
await next();
const ms = new Date() - start;
ctx.set('X-Response-Time', ms + 'ms');
}
async function index(ctx, next) {
await next();
if ('/' != ctx.url) return;
ctx.body = 'Howzit? From bar middleware bundle';
}
module.exports = [
responseTime,
index
];