fixed backward compat, and check if auto before getting addrs

This commit is contained in:
BPplays
2024-12-26 10:28:48 -08:00
parent 9e049f44e2
commit ca283c0da6
2 changed files with 31 additions and 29 deletions

View File

@ -8,7 +8,7 @@ cardsCacheCapacity: 100
listen: false listen: false
# Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled!
# - Use option "auto" to automatically detect support # - Use option "auto" to automatically detect support
# - Use "enabled" or "disabled" to enable or disable each protocol # - Use true or false (no qoutes) to enable or disable each protocol
protocol: protocol:
ipv4: auto ipv4: auto
ipv6: auto ipv6: auto

View File

@ -257,8 +257,8 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY); const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY);
const enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6); let enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6);
const enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4); let enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4);
const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME); const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME);
const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT); const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT);
@ -281,7 +281,8 @@ if (dnsPreferIPv6) {
console.log('Preferring IPv4 for DNS resolution'); console.log('Preferring IPv4 for DNS resolution');
} }
const ipOptions = ['enabled', 'auto', 'disabled'];
const ipOptions = [true, 'auto', false];
if (!ipOptions.includes(enableIPv6)) { if (!ipOptions.includes(enableIPv6)) {
console.error('`protocol: ipv6` option invalid\n use:', ipOptions); console.error('`protocol: ipv6` option invalid\n use:', ipOptions);
@ -292,7 +293,7 @@ if (!ipOptions.includes(enableIPv4)) {
process.exit(1); process.exit(1);
} }
if (enableIPv6 == 'disabled' && enableIPv4 == 'disabled') { if (enableIPv6 === false && enableIPv4 === false) {
console.error('error: You can\'t disable all internet protocols: at least IPv6 or IPv4 must be enabled.'); console.error('error: You can\'t disable all internet protocols: at least IPv6 or IPv4 must be enabled.');
process.exit(1); process.exit(1);
} }
@ -924,10 +925,13 @@ async function startHTTPorHTTPS(useIPv6, useIPv4) {
} }
async function startServer() { async function startServer() {
let useIPv6 = (enableIPv6 === 'enabled'); let useIPv6 = (enableIPv6 === true);
let useIPv4 = (enableIPv4 === 'enabled'); let useIPv4 = (enableIPv4 === true);
let hasIPv6, hasIPv4;
const [hasIPv6, hasIPv4] = await getHasIP();
if (enableIPv6 === 'auto' || enableIPv4 === 'auto') {
[hasIPv6, hasIPv4] = await getHasIP();
if (enableIPv6 === 'auto') { if (enableIPv6 === 'auto') {
useIPv6 = hasIPv6; useIPv6 = hasIPv6;
} }
@ -942,9 +946,6 @@ async function startServer() {
if (enableIPv4 === 'auto') { if (enableIPv4 === 'auto') {
useIPv4 = hasIPv4; useIPv4 = hasIPv4;
if (useIPv4) {
console.log(color.green('IPv4 support detected'));
}
} }
if (hasIPv4) { if (hasIPv4) {
if (useIPv4) { if (useIPv4) {
@ -953,6 +954,7 @@ async function startServer() {
console.log('IPv4 support detected'); console.log('IPv4 support detected');
} }
} }
}
if (enableIPv6 === 'auto' && enableIPv4 === 'auto') { if (enableIPv6 === 'auto' && enableIPv4 === 'auto') {