From 9bdfd5e0b1e973aacf730004d3914914bfa01cf8 Mon Sep 17 00:00:00 2001 From: David Ankin Date: Mon, 9 May 2022 03:16:12 -0400 Subject: [PATCH 1/4] use process.versions.node to dynamically detect ipv4 constant value --- bin/http-server | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/http-server b/bin/http-server index 7c597fa8..583db918 100755 --- a/bin/http-server +++ b/bin/http-server @@ -224,6 +224,7 @@ function listen(port) { if (argv.a && host !== '0.0.0.0') { logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`); } else { + var ipv4Family = parseInt(process.versions.node.split('.')[0], 10) >= 18 ? 4 : 'IPv4'; Object.keys(ifaces).forEach(function (dev) { ifaces[dev].forEach(function (details) { if (details.family === 'IPv4') { From 3b490a935c6ea4a65da6f48f6ee195e2a009cf51 Mon Sep 17 00:00:00 2001 From: David Ankin Date: Mon, 9 May 2022 03:16:43 -0400 Subject: [PATCH 2/4] use the new constant value to filter interfaces --- bin/http-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/http-server b/bin/http-server index 583db918..75c6c1ac 100755 --- a/bin/http-server +++ b/bin/http-server @@ -227,7 +227,7 @@ function listen(port) { var ipv4Family = parseInt(process.versions.node.split('.')[0], 10) >= 18 ? 4 : 'IPv4'; Object.keys(ifaces).forEach(function (dev) { ifaces[dev].forEach(function (details) { - if (details.family === 'IPv4') { + if (details.family === ipv4Family) { logger.info((' ' + protocol + details.address + ':' + chalk.green(port.toString()))); } }); From baec8c6574b8d86fd457505a3544c7ae6ceec90b Mon Sep 17 00:00:00 2001 From: Jade Michael Thornton Date: Tue, 31 May 2022 16:43:45 -0500 Subject: [PATCH 3/4] add explanatory comment --- bin/http-server | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/http-server b/bin/http-server index 75c6c1ac..f03c32d3 100755 --- a/bin/http-server +++ b/bin/http-server @@ -224,6 +224,7 @@ function listen(port) { if (argv.a && host !== '0.0.0.0') { logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`); } else { + // In Node 18+, interface family is a number, whereas earlier versions provide a string var ipv4Family = parseInt(process.versions.node.split('.')[0], 10) >= 18 ? 4 : 'IPv4'; Object.keys(ifaces).forEach(function (dev) { ifaces[dev].forEach(function (details) { From d6764567fd11b358c0ca52734e3bc20905f340da Mon Sep 17 00:00:00 2001 From: David Ankin Date: Thu, 13 Oct 2022 19:47:06 -0400 Subject: [PATCH 4/4] update to limit to 18.4 --- bin/http-server | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/http-server b/bin/http-server index f03c32d3..25f0da54 100755 --- a/bin/http-server +++ b/bin/http-server @@ -224,8 +224,9 @@ function listen(port) { if (argv.a && host !== '0.0.0.0') { logger.info(` ${protocol}${host}:${chalk.green(port.toString())}`); } else { - // In Node 18+, interface family is a number, whereas earlier versions provide a string - var ipv4Family = parseInt(process.versions.node.split('.')[0], 10) >= 18 ? 4 : 'IPv4'; + // In Node [18, 18.4), interface family is a number, whereas earlier versions provide a string + var nodeVer = process.versions.node.split('.'); + var ipv4Family = (nodeVer[0] === '18' && parseInt(nodeVer[1], 10) < 4) ? 4 : 'IPv4'; Object.keys(ifaces).forEach(function (dev) { ifaces[dev].forEach(function (details) { if (details.family === ipv4Family) {