Skip to content

Commit

Permalink
Allow deferring port to the OS
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen committed Aug 10, 2015
1 parent beb4672 commit b66ecfd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ var Server = function(inputStream, opts) {
}.bind(this));
}

Server.prototype.start = function(port) {
this.serverPort = port || 8001;
this.server = http.createServer(this.app).listen(this.serverPort);
Server.prototype.start = function(port, callback) {
this.serverPort = port != null ? port : 0;
this.server = http.createServer(this.app).listen(this.serverPort, function() {
this.serverPort = this.server.address().port;

if (callback && typeof callback === 'function') {
callback(this.serverPort);
}
}.bind(this));
}

Server.prototype.setInputStream = function(inputStream) {
Expand Down

0 comments on commit b66ecfd

Please sign in to comment.