thoughts/node_modules/express/lib/express.js
node_modules/express/lib/express.jsRaw
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
9'use strict';
10
11/**
12 * Module dependencies.
13 */
14
15var 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');
22
23/**
24 * Expose `createApplication()`.
25 */
26
27exports = module.exports = createApplication;
28
29/**
30 * Create an express application.
31 *
32 * @return {Function}
33 * @api public
34 */
35
36function createApplication() {
37 var app = function(req, res, next) {
38 app.handle(req, res, next);
39 };
40
41 mixin(app, EventEmitter.prototype, false);
42 mixin(app, proto, false);
43
44 app.request = { __proto__: req, app: app };
45 app.response = { __proto__: res, app: app };
46 app.init();
47 return app;
48}
49
50/**
51 * Expose the prototypes.
52 */
53
54exports.application = proto;
55exports.request = req;
56exports.response = res;
57
58/**
59 * Expose constructors.
60 */
61
62exports.Route = Route;
63exports.Router = Router;
64
65/**
66 * Expose middleware
67 */
68
69exports.query = require('./middleware/query');
70exports.static = require('serve-static');
71
72/**
73 * Replace removed middleware with an appropriate error message.
74 */
75
76[
77 'json',
78 'urlencoded',
79 'bodyParser',
80 'compress',
81 'cookieSession',
82 'session',
83 'logger',
84 'cookieParser',
85 'favicon',
86 'responseTime',
87 'errorHandler',
88 'timeout',
89 'methodOverride',
90 'vhost',
91 'csrf',
92 'directory',
93 'limit',
94 'multipart',
95 'staticCache',
96].forEach(function (name) {
97 Object.defineProperty(exports, name, {
98 get: function () {
99 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.');
100 },
101 configurable: true
102 });
103});