Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit dab03dc

Browse files
committed
Fix accessible hosts list in Node.js 18
The `family` property returned by `os.networkInterfaces()` is a `number` as of Node.js 18.0.0: https://nodejs.org/api/os.html#osnetworkinterfaces This meant no IPv4 addresses were being found, and subsequently none were logged to the console.
1 parent f4a70d5 commit dab03dc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/http-server/src/helpers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { networkInterfaces } from "os";
22

33
export function getAccessibleHosts(ipv4 = false): string[] {
44
const hosts: string[] = [];
5-
Object.values(networkInterfaces()).forEach((net) =>
5+
Object.values(networkInterfaces()).forEach((net) => {
66
net?.forEach(({ family, address }) => {
7-
if (!ipv4 || family === "IPv4") hosts.push(address);
8-
})
9-
);
7+
// @ts-expect-error the `family` property is numeric as of Node.js 18.0.0
8+
if (!ipv4 || family === "IPv4" || family === 4) hosts.push(address);
9+
});
10+
});
1011
return hosts;
1112
}

0 commit comments

Comments
 (0)