Skip to content

Instantly share code, notes, and snippets.

@RyanBreaker
Created May 25, 2015 05:44
Show Gist options
  • Save RyanBreaker/46ac4e15fb696de06c69 to your computer and use it in GitHub Desktop.
Save RyanBreaker/46ac4e15fb696de06c69 to your computer and use it in GitHub Desktop.
var koa = require('koa');
var app = koa();
// x-response-time
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
this.set('X-Response-Time', ms + 'ms');
});
// logger
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
console.log('%s %s - %s', this.method, this.url, ms);
});
// response
app.use(function *(){
this.body = 'Hello World';
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment