Skip to content

Commit a07121a

Browse files
Rahul SomasundaramKernelDeimos
authored andcommitted
set default listen on ipv4 and ipv6 interfaces
1 parent b7c46ac commit a07121a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

bin/http-server

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (argv.h || argv.help) {
2525
'',
2626
'options:',
2727
' -p --port Port to use. If 0, look for open port. [8080]',
28-
' -a Address to use [0.0.0.0]',
28+
' -a Address to use [0.0.0.0] or [::]',
2929
' -d Show directory listings [true]',
3030
' -i Display autoIndex [true]',
3131
' -g --gzip Serve gzip files when possible [false]',
@@ -66,7 +66,7 @@ if (argv.h || argv.help) {
6666
}
6767

6868
var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
69-
host = argv.a || '0.0.0.0',
69+
host = argv.a || '::',
7070
tls = argv.S || argv.tls,
7171
sslPassphrase = process.env.NODE_HTTP_SERVER_SSL_PASSPHRASE,
7272
proxy = argv.P || argv.proxy,
@@ -221,14 +221,17 @@ function listen(port) {
221221

222222
logger.info(chalk.yellow('\nAvailable on:'));
223223

224-
if (argv.a && host !== '0.0.0.0') {
224+
if (argv.a && (host !== '::' || host !== '0.0.0.0')) {
225225
logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`);
226226
} else {
227227
Object.keys(ifaces).forEach(function (dev) {
228228
ifaces[dev].forEach(function (details) {
229229
if (details.family === 'IPv4') {
230230
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
231231
}
232+
if (details.family === 'IPv6' && !details.address.startsWith("fe80") ) { // Ignoring Ipv6-Link Local addresses
233+
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
234+
}
232235
});
233236
});
234237
}
@@ -244,7 +247,10 @@ function listen(port) {
244247

245248
logger.info('Hit CTRL-C to stop the server');
246249
if (argv.o) {
247-
const openHost = host === '0.0.0.0' ? '127.0.0.1' : host;
250+
let openHost = host
251+
if ('::' === host || '0.0.0.0'===host){
252+
openHost = '127.0.0.1'
253+
}
248254
let openUrl = `${protocol}${openHost}:${port}`;
249255
if (typeof argv.o === 'string') {
250256
openUrl += argv.o[0] === '/' ? argv.o : '/' + argv.o;

0 commit comments

Comments
 (0)