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.

36 lines
752 B

  1. /*!
  2. * express
  3. * Copyright(c) 2009-2013 TJ Holowaychuk
  4. * Copyright(c) 2013 Roman Shtylman
  5. * Copyright(c) 2014-2015 Douglas Christopher Wilson
  6. * MIT Licensed
  7. */
  8. 'use strict';
  9. /**
  10. * Initialization middleware, exposing the
  11. * request and response to each other, as well
  12. * as defaulting the X-Powered-By header field.
  13. *
  14. * @param {Function} app
  15. * @return {Function}
  16. * @api private
  17. */
  18. exports.init = function(app){
  19. return function expressInit(req, res, next){
  20. if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
  21. req.res = res;
  22. res.req = req;
  23. req.next = next;
  24. req.__proto__ = app.request;
  25. res.__proto__ = app.response;
  26. res.locals = res.locals || Object.create(null);
  27. next();
  28. };
  29. };