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:
parent
c18c618a09
commit
b22ba1c03a
2 changed files with 9 additions and 2 deletions
5
.changeset/sixty-chicken-obey.md
Normal file
5
.changeset/sixty-chicken-obey.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix preview --host in Node.js 18
|
|
@ -126,13 +126,15 @@ export function resolveServerUrls({
|
||||||
let network: string | null = null;
|
let network: string | null = null;
|
||||||
|
|
||||||
if (networkLogging === 'visible') {
|
if (networkLogging === 'visible') {
|
||||||
const nodeVersion = Number(process.version.substring(1, process.version.indexOf('.', 5)));
|
|
||||||
const ipv4Networks = Object.values(os.networkInterfaces())
|
const ipv4Networks = Object.values(os.networkInterfaces())
|
||||||
.flatMap((networkInterface) => networkInterface ?? [])
|
.flatMap((networkInterface) => networkInterface ?? [])
|
||||||
.filter(
|
.filter(
|
||||||
(networkInterface) =>
|
(networkInterface) =>
|
||||||
networkInterface?.address &&
|
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) {
|
for (let { address: ipv4Address } of ipv4Networks) {
|
||||||
if (ipv4Address.includes('127.0.0.1')) {
|
if (ipv4Address.includes('127.0.0.1')) {
|
||||||
|
|
Loading…
Reference in a new issue