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.

43 lines
853 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. * Module dependencies.
  11. * @private
  12. */
  13. var setPrototypeOf = require('setprototypeof')
  14. /**
  15. * Initialization middleware, exposing the
  16. * request and response to each other, as well
  17. * as defaulting the X-Powered-By header field.
  18. *
  19. * @param {Function} app
  20. * @return {Function}
  21. * @api private
  22. */
  23. exports.init = function(app){
  24. return function expressInit(req, res, next){
  25. if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
  26. req.res = res;
  27. res.req = req;
  28. req.next = next;
  29. setPrototypeOf(req, app.request)
  30. setPrototypeOf(res, app.response)
  31. res.locals = res.locals || Object.create(null);
  32. next();
  33. };
  34. };