docs: update captains
[express.git] / lib / express.js
blobb4ef29963602f2728d1672e385d49ba2f1dadf04
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  */
9 'use strict';
11 /**
12  * Module dependencies.
13  */
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 Router = require('router');
20 var req = require('./request');
21 var res = require('./response');
23 /**
24  * Expose `createApplication()`.
25  */
27 exports = module.exports = createApplication;
29 /**
30  * Create an express application.
31  *
32  * @return {Function}
33  * @api public
34  */
36 function createApplication() {
37   var app = function(req, res, next) {
38     app.handle(req, res, next);
39   };
41   mixin(app, EventEmitter.prototype, false);
42   mixin(app, proto, false);
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   })
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   })
54   app.init();
55   return app;
58 /**
59  * Expose the prototypes.
60  */
62 exports.application = proto;
63 exports.request = req;
64 exports.response = res;
66 /**
67  * Expose constructors.
68  */
70 exports.Route = Router.Route;
71 exports.Router = Router;
73 /**
74  * Expose middleware
75  */
77 exports.json = bodyParser.json
78 exports.raw = bodyParser.raw
79 exports.static = require('serve-static');
80 exports.text = bodyParser.text
81 exports.urlencoded = bodyParser.urlencoded