summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2022-11-17 22:53:51 +0800
committerGravatar GitHub <noreply@github.com> 2022-11-17 22:53:51 +0800
commitb22ba1c03a3e384dad569feb38fa34ecf7ec3b93 (patch)
tree0b8294ff50e96d4d5cae5cc978b0c56d39c74d7d
parentc18c618a09ea5d3d40a64bc47c60c64a7a3be141 (diff)
downloadastro-b22ba1c03a3e384dad569feb38fa34ecf7ec3b93.tar.gz
astro-b22ba1c03a3e384dad569feb38fa34ecf7ec3b93.tar.zst
astro-b22ba1c03a3e384dad569feb38fa34ecf7ec3b93.zip
Fix preview --host in Node.js 18 (#5430)
Diffstat (limited to '')
-rw-r--r--.changeset/sixty-chicken-obey.md5
-rw-r--r--packages/astro/src/core/messages.ts6
2 files changed, 9 insertions, 2 deletions
diff --git a/.changeset/sixty-chicken-obey.md b/.changeset/sixty-chicken-obey.md
new file mode 100644
index 000000000..be19baace
--- /dev/null
+++ b/.changeset/sixty-chicken-obey.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix preview --host in Node.js 18
diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts
index 6020a45b7..3bfcbb61a 100644
--- a/packages/astro/src/core/messages.ts
+++ b/packages/astro/src/core/messages.ts
@@ -126,13 +126,15 @@ export function resolveServerUrls({
let network: string | null = null;
if (networkLogging === 'visible') {
- const nodeVersion = Number(process.version.substring(1, process.version.indexOf('.', 5)));
const ipv4Networks = Object.values(os.networkInterfaces())
.flatMap((networkInterface) => networkInterface ?? [])
.filter(
(networkInterface) =>
networkInterface?.address &&
- networkInterface?.family === (nodeVersion < 18 || nodeVersion >= 18.4 ? 'IPv4' : 4)
+ // Node < v18
+ ((typeof networkInterface.family === 'string' && networkInterface.family === 'IPv4') ||
+ // Node >= v18
+ (typeof networkInterface.family === 'number' && networkInterface.family === 4))
);
for (let { address: ipv4Address } of ipv4Networks) {
if (ipv4Address.includes('127.0.0.1')) {