-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved network url in (dev) cli (#72634)
Continues: #57882 with added test and rebased history Closes: #57882 --------- Co-authored-by: Ward Werbrouck <[email protected]>
- Loading branch information
Showing
4 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os from 'os' | ||
|
||
function getNetworkHosts(family: 'IPv4' | 'IPv6'): string[] { | ||
const interfaces = os.networkInterfaces() | ||
const hosts: string[] = [] | ||
|
||
Object.keys(interfaces).forEach((key) => { | ||
interfaces[key] | ||
?.filter((networkInterface) => { | ||
switch (networkInterface.family) { | ||
case 'IPv6': | ||
return ( | ||
family === 'IPv6' && | ||
networkInterface.scopeid === 0 && | ||
networkInterface.address !== '::1' | ||
) | ||
case 'IPv4': | ||
return family === 'IPv4' && networkInterface.address !== '127.0.0.1' | ||
default: | ||
return false | ||
} | ||
}) | ||
.forEach((networkInterface) => { | ||
if (networkInterface.address) { | ||
hosts.push(networkInterface.address) | ||
} | ||
}) | ||
}) | ||
|
||
return hosts | ||
} | ||
|
||
export function getNetworkHost(family: 'IPv4' | 'IPv6'): string | null { | ||
const hosts = getNetworkHosts(family) | ||
return hosts[0] ?? null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters