Skip to content

Instantly share code, notes, and snippets.

@chiefGui
Created July 31, 2014 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiefGui/bbfd22cce907e3512c1e to your computer and use it in GitHub Desktop.
Save chiefGui/bbfd22cce907e3512c1e 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