Skip to content

Commit

Permalink
Fix preview --host in Node.js 18 (#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Nov 17, 2022
1 parent c18c618 commit b22ba1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-chicken-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix preview --host in Node.js 18
6 changes: 4 additions & 2 deletions packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit b22ba1c

Please sign in to comment.