lib/middlewares/transform-response.js
function transformResponse(transform) {

  assert.ok(transform);
  assert.ok(transform instanceof Function);

  var originalStatus, originalJson, reqClosure;

  return function (req, res, next) {
    originalStatus = res.status;
    originalJson = res.json;
    reqClosure = req;
    res.status = setStatus;
    res.json = sendJson;
    return next();
  }

  function setStatus(status) {
    this.__status = status;
    return this;
  }

  function sendJson(body) {
    this.__body = body;
    var B = new Bundle(transform, reqClosure, this);
    originalStatus.call(this, B.status);
    return originalJson.call(this, B.body);
  }

}
function transformResponse(transform) {

  assert.ok(transform);
  assert.ok(transform instanceof Function);

  var originalStatus, originalJson, reqClosure;

  return function (req, res, next) {
    originalStatus = res.status;
    originalJson = res.json;
    reqClosure = req;
    res.status = setStatus;
    res.json = sendJson;
    return next();
  }

  function setStatus(status) {
    this.__status = status;
    return this;
  }

  function sendJson(body) {
    this.__body = body;
    var B = new Bundle(transform, reqClosure, this);
    originalStatus.call(this, B.status);
    return originalJson.call(this, B.body);
  }

}
function transformResponse ( transform ) { assert . ok ( transform ) ; assert . ok ( transform instanceof Function ) ; var originalStatus , originalJson , reqClosure ; return function ( req , res , next ) { originalStatus = res . status ; originalJson = res . json ; reqClosure = req ; res . status = setStatus ; res . json = sendJson ; return next ( ) ; } function setStatus ( status ) { this . __status = status ; return this ; } function sendJson ( body ) { this . __body = body ; var B = new Bundle ( transform , reqClosure , this ) ; originalStatus . call ( this , B . status ) ; return originalJson . call ( this , B . body ) ; } }
transformResponse - the factory for middleware that transforms response

@param  {Function} transform the function transfomrs `this.status` and `this.body`
@return {Function}           express middleware that transfomrs response
transformResponse - the factory for middleware that transforms response