Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ var name = 'static',
log = require('runner-logger').wrap(name);


function getExternalIp ( family ) {
var os = require('os'),
interfaces = os.networkInterfaces(),
index = 0,
interfaceName, iface;

for ( interfaceName in interfaces ) {
iface = interfaces[interfaceName];

index = 0;
while ( index < iface.length ) {
if ( iface[index].family === family && !iface[index].internal ) {
return iface[index].address;
}
++index;
}
}

return '0.0.0.0';
}


function start ( config, done ) {
var files = new (require('node-static').Server)(config.path, config.staticOptions),
server;
Expand Down Expand Up @@ -39,7 +61,7 @@ function start ( config, done ) {
// port can be 0 from the start
config.port = server.address().port;

config.uri = 'http://' + require('ip').address() + ':' + config.port + '/' + config.open;
config.uri = 'http://' + getExternalIp('IPv4') + ':' + config.port + '/' + config.open;

log.info('serving directory: ' + log.colors.bold(config.path));
log.info('web address: ' + log.colors.green.bold(config.uri));
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
},
"dependencies": {
"node-static": "^0.7.10",
"ip": "^1.1.5",
"opn": "^5.3.0",
"runner-logger": "^1.0.1"
},
Expand Down