fixed backward compat, and check if auto before getting addrs

ca283c0da63f7f000baf099447f6bd03d68da78c

BPplays <andymalbp@gmail.com>

2 files changed, +13 -11Showing whitespace changes
default/config.yaml+1 -1
@@ -8,7 +8,7 @@ cardsCacheCapacity: 100
88listen: false
99# Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled!
1010# - Use option "auto" to automatically detect support
1111# - Use "enabled"true or "disabled"false (no qoutes) to enable or disable each protocol
1212protocol:
1313 ipv4: auto
1414 ipv6: auto
server.js+12 -10
@@ -257,8 +257,8 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
257257
258258const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY);
259259
260260constlet enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6);
261261constlet enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4);
262262
263263const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME);
264264const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT);
@@ -281,7 +281,8 @@ if (dnsPreferIPv6) {
281281 console.log('Preferring IPv4 for DNS resolution');
282282}
283283
284-const ipOptions = ['enabled', 'auto', 'disabled'];
284+
285+const ipOptions = [true, 'auto', false];
285286
286287if (!ipOptions.includes(enableIPv6)) {
287288 console.error('`protocol: ipv6` option invalid\n use:', ipOptions);
@@ -292,7 +293,7 @@ if (!ipOptions.includes(enableIPv4)) {
292293 process.exit(1);
293294}
294295
295296if (enableIPv6 == 'disabled'= false && enableIPv4 === 'disabled'false) {
296297 console.error('error: You can\'t disable all internet protocols: at least IPv6 or IPv4 must be enabled.');
297298 process.exit(1);
298299}
@@ -924,10 +925,13 @@ async function startHTTPorHTTPS(useIPv6, useIPv4) {
924925}
925926
926927async function startServer() {
927928 let useIPv6 = (enableIPv6 === 'enabled'true);
928929 let useIPv4 = (enableIPv4 === 'enabled'true);
930+ let hasIPv6, hasIPv4;
931+
929932
930- const [hasIPv6, hasIPv4] = await getHasIP();
933+ if (enableIPv6 === 'auto' || enableIPv4 === 'auto') {
934+ [hasIPv6, hasIPv4] = await getHasIP();
931935 if (enableIPv6 === 'auto') {
932936 useIPv6 = hasIPv6;
933937 }
@@ -942,9 +946,6 @@ async function startServer() {
942946
943947 if (enableIPv4 === 'auto') {
944948 useIPv4 = hasIPv4;
945- if (useIPv4) {
946- console.log(color.green('IPv4 support detected'));
947- }
948949 }
949950 if (hasIPv4) {
950951 if (useIPv4) {
@@ -953,6 +954,7 @@ async function startServer() {
953954 console.log('IPv4 support detected');
954955 }
955956 }
957+ }
956958
957959
958960 if (enableIPv6 === 'auto' && enableIPv4 === 'auto') {