init.js
This file
Path
lib/middleware/init.js
43 lines · 853 bytes · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 43dff4c point at it.
docs: fix GitHub capitalizationPiper Chesterbefore adoption43dff4c
lines 1–43why, one step back1/*!2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2013 Roman Shtylman5 * Copyright(c) 2014-2015 Douglas Christopher Wilson6 * MIT Licensed7 */89'use strict';1011/**12 * Module dependencies.13 * @private14 */1516var setPrototypeOf = require('setprototypeof')1718/**19 * Initialization middleware, exposing the20 * request and response to each other, as well21 * as defaulting the X-Powered-By header field.22 *23 * @param {Function} app24 * @return {Function}25 * @api private26 */2728exports.init = function(app){29 return function expressInit(req, res, next){30 if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');31 req.res = res;32 res.req = req;33 req.next = next;3435 setPrototypeOf(req, app.request)36 setPrototypeOf(res, app.response)3738 res.locals = res.locals || Object.create(null);3940 next();41 };42};43