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
8listen: false8listen: 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 support10# - Use option "auto" to automatically detect support
11# - Use "enabled" or "disabled" to enable or disable each protocol11# - Use true or false (no qoutes) to enable or disable each protocol
12protocol:12protocol:
13 ipv4: auto13 ipv4: auto
14 ipv6: auto14 ipv6: auto
server.js+12 -10
@@ -257,8 +257,8 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
257257
258const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY);258const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY);
259259
260const enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6);260let enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6);
261const enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4);261let enableIPv4 = cliArguments.enableIPv4 ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4);
262262
263const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME);263const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME);
264const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT);264const 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}
283283
284const ipOptions = ['enabled', 'auto', 'disabled'];284
285const ipOptions = [true, 'auto', false];
285286
286if (!ipOptions.includes(enableIPv6)) {287if (!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}
294295
295if (enableIPv6 == 'disabled' && enableIPv4 == 'disabled') {296if (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}
925926
926async function startServer() {927async 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
929932
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() {
942946
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 }
956958
957959
958 if (enableIPv6 === 'auto' && enableIPv4 === 'auto') {960 if (enableIPv6 === 'auto' && enableIPv4 === 'auto') {