Created
July 31, 2014 12:15
-
-
Save chiefGui/bbfd22cce907e3512c1e 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