Skip to content

Commit

Permalink
allow loading of server/ as well as server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed May 28, 2012
1 parent d6f65ff commit 857d7d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
26 changes: 26 additions & 0 deletions bin/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true*/
(function () {
"use strict";

var app = require('../server.js')
;

function run() {
var config = require('../config')
, port = process.argv[2] || config.port || 4080
, server
;

function listening() {
console.info('Listening on ' + server.address().address + ':' + server.address().port);
}

server = app.listen(port, listening);
}

if (require.main === module) {
console.info("\n=== connect-vhoster running in stand-alone mode ===\n");
run();
}

}());
19 changes: 9 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true*/
(function () {
"use strict";

Expand Down Expand Up @@ -33,9 +34,9 @@

function eachHost(hostname) {
var serverPath = path.join(dirname, hostname)
, aliases = serverPath + '/aliases.js'
, server = serverPath + '/server.js'
, app = serverPath + '/app.js'
, aliases = serverPath + '/aliases'
, server = serverPath + '/server'
, app = serverPath + '/app'
, hostnames
, stats
;
Expand All @@ -56,7 +57,7 @@
}

if (!/\./.exec(hostname)) {
hostname += (config.defaultDomain)
hostname += (config.defaultDomain);
}

try {
Expand Down Expand Up @@ -91,7 +92,7 @@
} catch(e) {
hostnames = [];
}
hostnames.push(hostname)
hostnames.push(hostname);

hostnames.forEach(eachHostname);
}
Expand Down Expand Up @@ -142,15 +143,13 @@
console.info('Listening on ' + server.address().address + ':' + server.address().port);
}

if (port) {
server = app.listen(port, listening);
} else {
server = app.listen(listening);
}
server = app.listen(port, listening);
}

if (require.main === module) {
console.info("\n=== connect-vhoster running in stand-alone mode ===\n");
run();
}

module.exports = create(__dirname + '/vhosts');
}());

0 comments on commit 857d7d6

Please sign in to comment.