0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Fix preview --host in Node.js 18 (#5430)

This commit is contained in:
Bjorn Lu 2022-11-17 22:53:51 +08:00 committed by GitHub
parent c18c618a09
commit b22ba1c03a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix preview --host in Node.js 18

View file

@ -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')) {