This commit is contained in:
wuls 2023-04-28 18:00:33 +08:00 committed by Nate Moore
parent 9b33014958
commit bb0b0169c7
2 changed files with 1 additions and 14 deletions

View file

@ -1,13 +0,0 @@
import os from 'os'
export function getNetworkAddress(){
const interfaces = os.networkInterfaces();
const ips: string[] = [];
Object.keys(interfaces).forEach((nic) => {
interfaces[nic]!.forEach((details) => {
if (details.family === 'IPv4' && !details.internal) {
ips.push(details.address);
}
});
});
return ips?.[0] ? ips?.[0] : '127.0.0.1';
}

View file

@ -30,7 +30,7 @@ export function getResolvedHostForHttpServer(host: string | boolean) {
return '127.0.0.1';
} else if (host === true) {
// If passed --host in the CLI without arguments
return getNetworkAddress(); // undefined typically means 0.0.0.0 or :: (listen on all IPs)
return undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)
} else {
return host;
}