express.js
This file
Path
lib/express.js
111 lines · 2.2 KiB · JavaScript
Last changed by
Use Object.create to setup request & response prototypesDouglas Christopher Wilsonbefore adoption12ff56e
History of this fileTake it
The walk stopped after 200 commits: lines older than 2ac2509 point at it.
4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
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 */1415var EventEmitter = require('events').EventEmitter;16var mixin = require('merge-descriptors');17var proto = require('./application');18var Route = require('./router/route');19var Router = require('./router');20var req = require('./request');21var res = require('./response');2223/**24 * Expose `createApplication()`.25 */2627exports = module.exports = createApplication;2829/**30 * Create an express application.31 *32 * @return {Function}33 * @api public34 */3536function createApplication() {37 var app = function(req, res, next) {38 app.handle(req, res, next);39 };4041 mixin(app, EventEmitter.prototype, false);42 mixin(app, proto, false);43Use Object.create to setup request & response prototypesDouglas Christopher Wilsonbefore adoption12ff56e
lines 44–53why, one step back44 // expose the prototype that will get set on requests45 app.request = Object.create(req, {46 app: { configurable: true, enumerable: true, writable: true, value: app }47 })4849 // expose the prototype that will get set on responses50 app.response = Object.create(res, {51 app: { configurable: true, enumerable: true, writable: true, value: app }52 })534.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 54–111why, one step back54 app.init();55 return app;56}5758/**59 * Expose the prototypes.60 */6162exports.application = proto;63exports.request = req;64exports.response = res;6566/**67 * Expose constructors.68 */6970exports.Route = Route;71exports.Router = Router;7273/**74 * Expose middleware75 */7677exports.query = require('./middleware/query');78exports.static = require('serve-static');7980/**81 * Replace removed middleware with an appropriate error message.82 */8384[85 'json',86 'urlencoded',87 'bodyParser',88 'compress',89 'cookieSession',90 'session',91 'logger',92 'cookieParser',93 'favicon',94 'responseTime',95 'errorHandler',96 'timeout',97 'methodOverride',98 'vhost',99 'csrf',100 'directory',101 'limit',102 'multipart',103 'staticCache',104].forEach(function (name) {105 Object.defineProperty(exports, name, {106 get: function () {107 throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');108 },109 configurable: true110 });111});