Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set default listener on ipv4 and ipv6 interfaces #830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions bin/http-server
Expand Up @@ -25,7 +25,7 @@ if (argv.h || argv.help) {
'',
'options:',
' -p --port Port to use. If 0, look for open port. [8080]',
' -a Address to use [0.0.0.0]',
' -a Address to use [0.0.0.0] or [::]',
' -d Show directory listings [true]',
' -i Display autoIndex [true]',
' -g --gzip Serve gzip files when possible [false]',
Expand Down Expand Up @@ -66,7 +66,7 @@ if (argv.h || argv.help) {
}

var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
host = argv.a || '0.0.0.0',
host = argv.a || '::',
tls = argv.S || argv.tls,
sslPassphrase = process.env.NODE_HTTP_SERVER_SSL_PASSPHRASE,
proxy = argv.P || argv.proxy,
Expand Down Expand Up @@ -221,14 +221,17 @@ function listen(port) {

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

if (argv.a && host !== '0.0.0.0') {
if (argv.a && (host !== '::' || host !== '0.0.0.0')) {
logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`);
} else {
Object.keys(ifaces).forEach(function (dev) {
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
}
if (details.family === 'IPv6' && !details.address.startsWith("fe80") ) { // Ignoring Ipv6-Link Local addresses
logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString())));
}
});
});
}
Expand All @@ -244,7 +247,10 @@ function listen(port) {

logger.info('Hit CTRL-C to stop the server');
if (argv.o) {
const openHost = host === '0.0.0.0' ? '127.0.0.1' : host;
let openHost = host
if ('::' === host || '0.0.0.0'===host){
openHost = '127.0.0.1'
}
let openUrl = `${protocol}${openHost}:${port}`;
if (typeof argv.o === 'string') {
openUrl += argv.o[0] === '/' ? argv.o : '/' + argv.o;
Expand Down