second
[josuexyz/.git] / node_modules / express / lib / express.js
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
15 var bodyParser = require('body-parser')
16 var EventEmitter = require('events').EventEmitter;
17 var mixin = require('merge-descriptors');
18 var proto = require('./application');
19 var Route = require('./router/route');
20 var Router = require('./router');
21 var req = require('./request');
22 var res = require('./response');
23
24 /**
25  * Expose `createApplication()`.
26  */
27
28 exports = module.exports = createApplication;
29
30 /**
31  * Create an express application.
32  *
33  * @return {Function}
34  * @api public
35  */
36
37 function createApplication() {
38   var app = function(req, res, next) {
39     app.handle(req, res, next);
40   };
41
42   mixin(app, EventEmitter.prototype, false);
43   mixin(app, proto, false);
44
45   // expose the prototype that will get set on requests
46   app.request = Object.create(req, {
47     app: { configurable: true, enumerable: true, writable: true, value: app }
48   })
49
50   // expose the prototype that will get set on responses
51   app.response = Object.create(res, {
52     app: { configurable: true, enumerable: true, writable: true, value: app }
53   })
54
55   app.init();
56   return app;
57 }
58
59 /**
60  * Expose the prototypes.
61  */
62
63 exports.application = proto;
64 exports.request = req;
65 exports.response = res;
66
67 /**
68  * Expose constructors.
69  */
70
71 exports.Route = Route;
72 exports.Router = Router;
73
74 /**
75  * Expose middleware
76  */
77
78 exports.json = bodyParser.json
79 exports.query = require('./middleware/query');
80 exports.static = require('serve-static');
81 exports.urlencoded = bodyParser.urlencoded
82
83 /**
84  * Replace removed middleware with an appropriate error message.
85  */
86
87 var removedMiddlewares = [
88   '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 ]
106
107 removedMiddlewares.forEach(function (name) {
108   Object.defineProperty(exports, name, {
109     get: function () {
110       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.');
111     },
112     configurable: true
113   });
114 });