Skip to content

Instantly share code, notes, and snippets.

@PandaWhisperer
Created April 7, 2015 23:05
Show Gist options
  • Save PandaWhisperer/cf0656c7c2b93702ccea to your computer and use it in GitHub Desktop.
Save PandaWhisperer/cf0656c7c2b93702ccea to your computer and use it in GitHub Desktop.
koa = require("koa")
app = koa()
# x-response-time
app.use (next) ->
start = new Date
yield next
ms = new Date - start
@set 'X-Response-Time', ms + 'ms'
# logger
app.use (next) ->
start = new Date
yield next
ms = new Date - start
console.log '%s %s - %s', this.method, this.url, ms
# response
app.use (next) ->
this.body = "Hello World"
yield next
app.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment