Created
May 25, 2015 05:44
-
-
Save RyanBreaker/46ac4e15fb696de06c69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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