Skip to content

Commit

Permalink
use port to build address
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Hoffmann committed May 23, 2015
1 parent f032de8 commit ccd846d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ var utils = function() {
*
* @returns IPv4 address.
*/
var currentAddress = function() {
var currentAddress = function(port) {
var networkInterfaces = os.networkInterfaces( );
for (var networkInterface in networkInterfaces) {
var iface = networkInterfaces[networkInterface];

for (var i = 0; i < iface.length; i++) {
var name = iface[i];
if (name.address !== "127.0.0.1" && name.family === "IPv4" && !name.internal) {
return "http://" + name.address;
return "http://" + name.address + ":" + port;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("utils", function(){
]}
);

assert.equal(utils.currentAddress(), "http://192.168.0.7");
assert.equal(utils.currentAddress(9), "http://192.168.0.7:9");
});

it("shouldn't return network address if no external IPv4 is available", function(){
Expand All @@ -40,7 +40,7 @@ describe("utils", function(){
]}
);

assert.equal(utils.currentAddress(), undefined);
assert.equal(utils.currentAddress(9), undefined);
});
});
});
Expand Down

0 comments on commit ccd846d

Please sign in to comment.