Created
August 30, 2017 03:24
-
-
Save suncn/3ebd79318ee5a0903a445aae82be7a4f to your computer and use it in GitHub Desktop.
atom-live-server locaip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var os=require('os'), | |
iptable={}, | |
ifaces=os.networkInterfaces(); | |
for (var dev in ifaces) { | |
ifaces[dev].forEach(function(details,alias){ | |
if ((details.family=='IPv4') && (details.internal == false)) { | |
// iptable[dev+(alias?':'+alias:'')]=details.address; | |
iptable['localIP'] = details.address; | |
} | |
}); | |
} | |
var address = server.address(); | |
var serveHost = address.address === "0.0.0.0" ? iptable.localIP : address.address; | |
var openHost = host === "0.0.0.0" ? iptable.localIP : host; | |
var serveURL = protocol + '://' + serveHost + ':' + address.port; | |
var openURL = protocol + '://' + openHost + ':' + address.port; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment