UNPKG

2.22 kBJavaScriptView Raw
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 // 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
62exports.application = proto;
63exports.request = req;
64exports.response = res;
65
66/**
67 * Expose constructors.
68 */
69
70exports.Route = Route;
71exports.Router = Router;
72
73/**
74 * Expose middleware
75 */
76
77exports.query = require('./middleware/query');
78exports.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});