Skip to content

Instantly share code, notes, and snippets.

@trezy
Created August 1, 2016 18:42
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 trezy/d933b8c78655a51126ba95f9f9286c8f to your computer and use it in GitHub Desktop.
Save trezy/d933b8c78655a51126ba95f9f9286c8f to your computer and use it in GitHub Desktop.
function * bodyBuilder (next) {
this.body = {
links: {},
meta: {
start_ms: Date.now()
}
}
yield next
if (Array.isArray(this.body.data)) {
this.body.meta.count = this.body.data.length
}
this.body.meta.end_ms = Date.now()
this.body.meta.response_ms = (this.body.meta.end_ms - this.body.meta.start_ms)
}
module.exports = function () {
return bodyBuilder
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment