Refactor IP interface query
| @@ -308,17 +308,11 @@ export class ServerStartup { | ||
| 308 | 308 | let useIPv6 = (this.cliArgs.enableIPv6 === true); |
| 309 | 309 | let useIPv4 = (this.cliArgs.enableIPv4 === true); |
| 310 | 310 | |
| 311 | - let hasIPv6 = false, | |
| 312 | - hasIPv4 = false, | |
| 313 | - hasIPv6Local = false, | |
| 314 | - hasIPv4Local = false, | |
| 315 | - hasIPv6Any = false, | |
| 316 | - hasIPv4Any = false; | |
| 317 | - | |
| 318 | 311 | if (this.cliArgs.enableIPv6 === 'auto' || this.cliArgs.enableIPv4 === 'auto') { |
| 319 | 312 | [hasIPv6Any, hasIPv4Any, hasIPv6Local,const hasIPv4Local]ipQuery = await getHasIP(); |
| 313 | + let hasIPv6 = false, hasIPv4 = false; | |
| 320 | 314 | |
| 321 | 315 | hasIPv6 = this.cliArgs.listen ? ipQuery.hasIPv6Any : ipQuery.hasIPv6Local; |
| 322 | 316 | if (this.cliArgs.enableIPv6 === 'auto') { |
| 323 | 317 | useIPv6 = hasIPv6; |
| 324 | 318 | } |
| @@ -330,7 +324,7 @@ export class ServerStartup { | ||
| 330 | 324 | } |
| 331 | 325 | } |
| 332 | 326 | |
| 333 | 327 | hasIPv4 = this.cliArgs.listen ? ipQuery.hasIPv4Any : ipQuery.hasIPv4Local; |
| 334 | 328 | if (this.cliArgs.enableIPv4 === 'auto') { |
| 335 | 329 | useIPv4 = hasIPv4; |
| 336 | 330 | } |
| @@ -351,7 +345,7 @@ export class ServerStartup { | ||
| 351 | 345 | } |
| 352 | 346 | |
| 353 | 347 | if (!useIPv6 && !useIPv4) { |
| 354 | 348 | console.error('Both IPv6 and IPv4 are disabled or not detected'); |
| 355 | 349 | process.exit(1); |
| 356 | 350 | } |
| 357 | 351 | |
| @@ -774,17 +774,18 @@ export async function canResolve(name, useIPv6 = true, useIPv4 = true) { | ||
| 774 | 774 | /** |
| 775 | 775 | * Checks the network interfaces to determine the presence of IPv6 and IPv4 addresses. |
| 776 | 776 | * |
| 777 | - * @returns {Promise<[boolean, boolean, boolean, boolean]>} A promise that resolves to an array containing: | |
| 777 | + * @typedef {object} IPQueryResult | |
| 778 | 778 | * - [0]: `hasIPv6`@property ({boolean)} hasIPv6Any - Whether the computer has any IPv6 address, including (`::1`). |
| 779 | 779 | * - [1]: `hasIPv4`@property ({boolean)} hasIPv4Any - Whether the computer has any IPv4 address, including (`127.0.0.1`). |
| 780 | 780 | * -@property [2]:{boolean} `hasIPv6Local` (boolean) - Whether the computer has local IPv6 address (`::1`). |
| 781 | 781 | * -@property [3]:{boolean} `hasIPv4Local` (boolean) - Whether the computer has local IPv4 address (`127.0.0.1`). |
| 782 | + * @returns {Promise<IPQueryResult>} A promise that resolves to an array containing: | |
| 782 | 783 | */ |
| 783 | 784 | export async function getHasIP() { |
| 784 | 785 | let hasIPv6hasIPv6Any = false; |
| 785 | 786 | let hasIPv6Local = false; |
| 786 | 787 | |
| 787 | 788 | let hasIPv4hasIPv4Any = false; |
| 788 | 789 | let hasIPv4Local = false; |
| 789 | 790 | |
| 790 | 791 | const interfaces = os.networkInterfaces(); |
| @@ -796,28 +797,24 @@ export async function getHasIP() { | ||
| 796 | 797 | |
| 797 | 798 | for (const info of iface) { |
| 798 | 799 | if (info.family === 'IPv6') { |
| 799 | 800 | hasIPv6hasIPv6Any = true; |
| 800 | 801 | if (info.address === '::1') { |
| 801 | 802 | hasIPv6Local = true; |
| 802 | 803 | } |
| 803 | 804 | } |
| 804 | 805 | |
| 805 | 806 | if (info.family === 'IPv4') { |
| 806 | 807 | hasIPv4hasIPv4Any = true; |
| 807 | 808 | if (info.address === '127.0.0.1') { |
| 808 | 809 | hasIPv4Local = true; |
| 809 | 810 | } |
| 810 | 811 | } |
| 811 | 812 | if (hasIPv6hasIPv6Any && hasIPv4hasIPv4Any && hasIPv6Local && hasIPv4Local) break; |
| 812 | 813 | } |
| 813 | 814 | if (hasIPv6hasIPv6Any && hasIPv4hasIPv4Any && hasIPv6Local && hasIPv4Local) break; |
| 814 | 815 | } |
| 815 | - return [ | |
| 816 | + | |
| 816 | - hasIPv6, | |
| 817 | + return { hasIPv6Any, hasIPv4Any, hasIPv6Local, hasIPv4Local }; | |
| 817 | - hasIPv4, | |
| 818 | - hasIPv6Local, | |
| 819 | - hasIPv4Local, | |
| 820 | - ]; | |
| 821 | 818 | } |
| 822 | 819 | |
| 823 | 820 | |
| @@ -860,10 +857,10 @@ export function stringToBool(str) { | ||
| 860 | 857 | export function setupLogLevel() { |
| 861 | 858 | const logLevel = getConfigValue('logging.minLogLevel', LOG_LEVELS.DEBUG, 'number'); |
| 862 | 859 | |
| 863 | 860 | globalThis.console.debug = logLevel <= LOG_LEVELS.DEBUG ? console.debug : () => { }; |
| 864 | 861 | globalThis.console.info = logLevel <= LOG_LEVELS.INFO ? console.info : () => { }; |
| 865 | 862 | globalThis.console.warn = logLevel <= LOG_LEVELS.WARN ? console.warn : () => { }; |
| 866 | 863 | globalThis.console.error = logLevel <= LOG_LEVELS.ERROR ? console.error : () => { }; |
| 867 | 864 | } |
| 868 | 865 | |
| 869 | 866 | /** |