Skip to content

Commit

Permalink
Make server port a command-line option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Link committed Apr 10, 2012
1 parent 85801dd commit 17071d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions example/socketio/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
if (typeof process.argv[2] == 'undefined') {
console.error('Usage: node server <port>');
return;
}

var http = require('http');
var url = require('url');
var fs = require('fs');
Expand Down Expand Up @@ -29,7 +34,7 @@ socketioserver.sockets.on('connection', function(connection) {
pub.connect('chat');
});

httpserver.listen(8080, '0.0.0.0');
httpserver.listen(process.argv[2], '0.0.0.0');

// ==== boring detail

Expand All @@ -42,7 +47,7 @@ function handler(req, res) {
fs.readFile(__dirname + '/index.html', function(err, data){
if (err) return send404(res);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data, 'utf8');
res.write(data.toString('utf8').replace('{{PORT}}', process.argv[2]), 'utf8');
res.end();
});
break;
Expand Down

0 comments on commit 17071d5

Please sign in to comment.