You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
662 B

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