]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/connect/lib/connect.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / connect / lib / connect.js
1
2 /*!
3  * Connect
4  * Copyright(c) 2010 Sencha Inc.
5  * Copyright(c) 2011 TJ Holowaychuk
6  * MIT Licensed
7  */
8
9 /**
10  * Module dependencies.
11  */
12
13 var HTTPServer = require('./http').Server
14   , HTTPSServer = require('./https').Server
15   , fs = require('fs');
16
17 // node patches
18
19 require('./patch');
20
21 // expose createServer() as the module
22
23 exports = module.exports = createServer;
24
25 /**
26  * Framework version.
27  */
28
29 exports.version = '1.4.0';
30
31 /**
32  * Initialize a new `connect.HTTPServer` with the middleware
33  * passed to this function. When an object is passed _first_,
34  * we assume these are the tls options, and return a `connect.HTTPSServer`.
35  *
36  * Examples:
37  *
38  * An example HTTP server, accepting several middleware.
39  *
40  *     var server = connect.createServer(
41  *         connect.logger()
42  *       , connect.static(__dirname + '/public')
43  *     );
44  *
45  * An HTTPS server, utilizing the same middleware as above.
46  *
47  *     var server = connect.createServer(
48  *         { key: key, cert: cert }
49  *       , connect.logger()
50  *       , connect.static(__dirname + '/public')
51  *     );
52  *
53  * Alternatively with connect 1.0 we may omit `createServer()`.
54  *
55  *     connect(
56  *         connect.logger()
57  *       , connect.static(__dirname + '/public')
58  *     ).listen(3000);
59  *
60  * @param  {Object|Function} ...
61  * @return {Server}
62  * @api public
63  */
64
65 function createServer() {
66   if ('object' == typeof arguments[0]) {
67     return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
68   } else {
69     return new HTTPServer(Array.prototype.slice.call(arguments));
70   }
71 };
72
73 // support connect.createServer()
74
75 exports.createServer = createServer;
76
77 // auto-load getters
78
79 exports.middleware = {};
80
81 /**
82  * Auto-load bundled middleware with getters.
83  */
84
85 fs.readdirSync(__dirname + '/middleware').forEach(function(filename){
86   if (/\.js$/.test(filename)) {
87     var name = filename.substr(0, filename.lastIndexOf('.'));
88     exports.middleware.__defineGetter__(name, function(){
89       return require('./middleware/' + name);
90     });
91   }
92 });
93
94 // expose utils
95
96 exports.utils = require('./utils');
97
98 // expose getters as first-class exports
99
100 exports.utils.merge(exports, exports.middleware);
101
102 // expose constructors
103
104 exports.HTTPServer = HTTPServer;
105 exports.HTTPSServer = HTTPSServer;
106