NewsBlur/node/node_modules/express/lib/middleware/init.js

44 lines
853 B
JavaScript
Raw Normal View History

2016-11-29 18:29:50 -08:00
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
2013-03-15 17:18:36 -07:00
*/
2016-11-29 18:29:50 -08:00
'use strict';
2013-03-15 17:18:36 -07:00
/**
* Module dependencies.
* @private
*/
var setPrototypeOf = require('setprototypeof')
2013-03-15 17:18:36 -07:00
/**
* Initialization middleware, exposing the
2016-11-29 18:29:50 -08:00
* request and response to each other, as well
2013-03-15 17:18:36 -07:00
* as defaulting the X-Powered-By header field.
*
* @param {Function} app
* @return {Function}
* @api private
*/
exports.init = function(app){
return function expressInit(req, res, next){
if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
req.res = res;
res.req = req;
req.next = next;
setPrototypeOf(req, app.request)
setPrototypeOf(res, app.response)
2013-03-15 17:18:36 -07:00
2016-11-29 18:29:50 -08:00
res.locals = res.locals || Object.create(null);
2013-03-15 17:18:36 -07:00
next();
2016-11-29 18:29:50 -08:00
};
2013-03-15 17:18:36 -07:00
};
2016-11-29 18:29:50 -08:00