express.js
This file
Path
lib/express.js
112 lines · 2.3 KiB · JavaScript
Last changed by
Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
History of this fileTake it
The walk stopped after 200 commits: lines older than dc48f27 point at it.
deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 1–14why, 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 */14Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
line 15why, one step back15var bodyParser = require('body-parser')deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 16–44why, one step back16var EventEmitter = require('events').EventEmitter;17var mixin = require('merge-descriptors');18var proto = require('./application');19var Route = require('./router/route');20var Router = require('./router');21var req = require('./request');22var res = require('./response');2324/**25 * Expose `createApplication()`.26 */2728exports = module.exports = createApplication;2930/**31 * Create an express application.32 *33 * @return {Function}34 * @api public35 */3637function createApplication() {38 var app = function(req, res, next) {39 app.handle(req, res, next);40 };4142 mixin(app, EventEmitter.prototype, false);43 mixin(app, proto, false);44Use Object.create to setup request & response prototypesDouglas Christopher Wilsonbefore adoption12ff56e
lines 45–54why, one step back45 // expose the prototype that will get set on requests46 app.request = Object.create(req, {47 app: { configurable: true, enumerable: true, writable: true, value: app }48 })4950 // expose the prototype that will get set on responses51 app.response = Object.create(res, {52 app: { configurable: true, enumerable: true, writable: true, value: app }53 })54deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 55–77why, one step back55 app.init();56 return app;57}5859/**60 * Expose the prototypes.61 */6263exports.application = proto;64exports.request = req;65exports.response = res;6667/**68 * Expose constructors.69 */7071exports.Route = Route;72exports.Router = Router;7374/**75 * Expose middleware76 */77Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
line 78why, one step back78exports.json = bodyParser.jsondeps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 79–80why, one step back79exports.query = require('./middleware/query');80exports.static = require('serve-static');Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
line 81why, one step back81exports.urlencoded = bodyParser.urlencodeddeps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 82–86why, one step back8283/**84 * Replace removed middleware with an appropriate error message.85 */86Add express.json and express.urlencoded to parse bodiesDouglas Christopher Wilsonbefore adoptionc0136d8
line 87why, one step back87;[deps: update example dependenciesDouglas Christopher Wilsonbefore adoptiondc48f27
lines 88–112why, one step back88 'bodyParser',89 'compress',90 'cookieSession',91 'session',92 'logger',93 'cookieParser',94 'favicon',95 'responseTime',96 'errorHandler',97 'timeout',98 'methodOverride',99 'vhost',100 'csrf',101 'directory',102 'limit',103 'multipart',104 'staticCache',105].forEach(function (name) {106 Object.defineProperty(exports, name, {107 get: function () {108 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.');109 },110 configurable: true111 });112});