init.js 570 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Initialization middleware, exposing the
  3. * request and response to eachother, as well
  4. * as defaulting the X-Powered-By header field.
  5. *
  6. * @param {Function} app
  7. * @return {Function}
  8. * @api private
  9. */
  10. exports.init = function(app){
  11. return function expressInit(req, res, next){
  12. if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
  13. req.res = res;
  14. res.req = req;
  15. req.next = next;
  16. req.__proto__ = app.request;
  17. res.__proto__ = app.response;
  18. res.locals = res.locals || Object.create(null);
  19. next();
  20. };
  21. };