fixed backward compat, and check if auto before getting addrs
| @@ -8,7 +8,7 @@ cardsCacheCapacity: 100 | |||
| 8 | listen: false | 8 | listen: false |
| 9 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! | 9 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! |
| 10 | # - Use option "auto" to automatically detect support | 10 | # - Use option "auto" to automatically detect support |
| 11 | # - Use "enabled" or "disabled" to enable or disable each protocol | 11 | # - Use true or false (no qoutes) to enable or disable each protocol |
| 12 | protocol: | 12 | protocol: |
| 13 | ipv4: auto | 13 | ipv4: auto |
| 14 | ipv6: auto | 14 | ipv6: auto |
| @@ -257,8 +257,8 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS); | |||
| 257 | 257 | ||
| 258 | const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY); | 258 | const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY); |
| 259 | 259 | ||
| 260 | const enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6); | 260 | let enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6); |
| 261 | const enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4); | 261 | let enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4); |
| 262 | 262 | ||
| 263 | const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME); | 263 | const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME); |
| 264 | const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT); | 264 | const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT); |
| @@ -281,7 +281,8 @@ if (dnsPreferIPv6) { | |||
| 281 | console.log('Preferring IPv4 for DNS resolution'); | 281 | console.log('Preferring IPv4 for DNS resolution'); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | const ipOptions = ['enabled', 'auto', 'disabled']; | 284 | |
| 285 | const ipOptions = [true, 'auto', false]; | ||
| 285 | 286 | ||
| 286 | if (!ipOptions.includes(enableIPv6)) { | 287 | if (!ipOptions.includes(enableIPv6)) { |
| 287 | console.error('`protocol: ipv6` option invalid\n use:', ipOptions); | 288 | console.error('`protocol: ipv6` option invalid\n use:', ipOptions); |
| @@ -292,7 +293,7 @@ if (!ipOptions.includes(enableIPv4)) { | |||
| 292 | process.exit(1); | 293 | process.exit(1); |
| 293 | } | 294 | } |
| 294 | 295 | ||
| 295 | if (enableIPv6 == 'disabled' && enableIPv4 == 'disabled') { | 296 | if (enableIPv6 === false && enableIPv4 === false) { |
| 296 | console.error('error: You can\'t disable all internet protocols: at least IPv6 or IPv4 must be enabled.'); | 297 | console.error('error: You can\'t disable all internet protocols: at least IPv6 or IPv4 must be enabled.'); |
| 297 | process.exit(1); | 298 | process.exit(1); |
| 298 | } | 299 | } |
| @@ -924,10 +925,13 @@ async function startHTTPorHTTPS(useIPv6, useIPv4) { | |||
| 924 | } | 925 | } |
| 925 | 926 | ||
| 926 | async function startServer() { | 927 | async function startServer() { |
| 927 | let useIPv6 = (enableIPv6 === 'enabled'); | 928 | let useIPv6 = (enableIPv6 === true); |
| 928 | let useIPv4 = (enableIPv4 === 'enabled'); | 929 | let useIPv4 = (enableIPv4 === true); |
| 930 | let hasIPv6, hasIPv4; | ||
| 931 | |||
| 929 | 932 | ||
| 930 | const [hasIPv6, hasIPv4] = await getHasIP(); | 933 | if (enableIPv6 === 'auto' || enableIPv4 === 'auto') { |
| 934 | [hasIPv6, hasIPv4] = await getHasIP(); | ||
| 931 | if (enableIPv6 === 'auto') { | 935 | if (enableIPv6 === 'auto') { |
| 932 | useIPv6 = hasIPv6; | 936 | useIPv6 = hasIPv6; |
| 933 | } | 937 | } |
| @@ -942,9 +946,6 @@ async function startServer() { | |||
| 942 | 946 | ||
| 943 | if (enableIPv4 === 'auto') { | 947 | if (enableIPv4 === 'auto') { |
| 944 | useIPv4 = hasIPv4; | 948 | useIPv4 = hasIPv4; |
| 945 | if (useIPv4) { | ||
| 946 | console.log(color.green('IPv4 support detected')); | ||
| 947 | } | ||
| 948 | } | 949 | } |
| 949 | if (hasIPv4) { | 950 | if (hasIPv4) { |
| 950 | if (useIPv4) { | 951 | if (useIPv4) { |
| @@ -953,6 +954,7 @@ async function startServer() { | |||
| 953 | console.log('IPv4 support detected'); | 954 | console.log('IPv4 support detected'); |
| 954 | } | 955 | } |
| 955 | } | 956 | } |
| 957 | } | ||
| 956 | 958 | ||
| 957 | 959 | ||
| 958 | if (enableIPv6 === 'auto' && enableIPv4 === 'auto') { | 960 | if (enableIPv6 === 'auto' && enableIPv4 === 'auto') { |