Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
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 EventEmitter = require('events').EventEmitter;
16
var mixin = require('merge-descriptors');
17
var proto = require('./application');
18
var Route = require('./router/route');
19
var Router = require('./router');
20
var req = require('./request');
21
var res = require('./response');
22
23
/**
24
* Expose `createApplication()`.
25
*/
26
27
exports = module.exports = createApplication;
28
29
/**
30
* Create an express application.
31
*
32
* @return {Function}
33
* @api public
34
*/
35
36
function 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
// expose the prototype that will get set on requests
45
app.request = Object.create(req, {
46
app: { configurable: true, enumerable: true, writable: true, value: app }
47
})
48
49
// expose the prototype that will get set on responses
50
app.response = Object.create(res, {
51
app: { configurable: true, enumerable: true, writable: true, value: app }
52
})
53
54
app.init();
55
return app;
56
}
57
58
/**
59
* Expose the prototypes.
60
*/
61
62
exports.application = proto;
63
exports.request = req;
64
exports.response = res;
65
66
/**
67
* Expose constructors.
68
*/
69
70
exports.Route = Route;
71
exports.Router = Router;
72
73
/**
74
* Expose middleware
75
*/
76
77
exports.query = require('./middleware/query');
78
exports.static = require('serve-static');
79
80
/**
81
* Replace removed middleware with an appropriate error message.
82
*/
83
84
[
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: true
110
});
111
});
112
113