4 * Copyright(c) 2010 Sencha Inc.
5 * Copyright(c) 2011 TJ Holowaychuk
10 * Module dependencies.
13 var HTTPServer = require('./http').Server
14 , HTTPSServer = require('./https').Server
21 // expose createServer() as the module
23 exports = module.exports = createServer;
29 exports.version = '1.6.0';
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`.
38 * An example HTTP server, accepting several middleware.
40 * var server = connect.createServer(
42 * , connect.static(__dirname + '/public')
45 * An HTTPS server, utilizing the same middleware as above.
47 * var server = connect.createServer(
48 * { key: key, cert: cert }
50 * , connect.static(__dirname + '/public')
53 * Alternatively with connect 1.0 we may omit `createServer()`.
57 * , connect.static(__dirname + '/public')
60 * @param {Object|Function} ...
65 function createServer() {
66 if ('object' == typeof arguments[0]) {
67 return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
69 return new HTTPServer(Array.prototype.slice.call(arguments));
73 // support connect.createServer()
75 exports.createServer = createServer;
79 exports.middleware = {};
82 * Auto-load bundled middleware with getters.
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);
96 exports.utils = require('./utils');
98 // expose getters as first-class exports
100 exports.utils.merge(exports, exports.middleware);
102 // expose constructors
104 exports.HTTPServer = HTTPServer;
105 exports.HTTPSServer = HTTPSServer;