fixed cli args and logic bug
| @@ -244,6 +244,12 @@ app.use(helmet({ | ||
| 244 | 244 | app.use(compression()); |
| 245 | 245 | app.use(responseTime()); |
| 246 | 246 | |
| 247 | +function stringToBool(str) { | |
| 248 | + if (str === 'true') return true; | |
| 249 | + if (str === 'false') return false; | |
| 250 | + return str; // or throw an error | |
| 251 | +} | |
| 252 | + | |
| 247 | 253 | const server_port = cliArguments.port ?? process.env.SILLY_TAVERN_PORT ?? getConfigValue('port', DEFAULT_PORT); |
| 248 | 254 | const autorun = (cliArguments.autorun ?? getConfigValue('autorun', DEFAULT_AUTORUN)) && !cliArguments.ssl; |
| 249 | 255 | const listen = cliArguments.listen ?? getConfigValue('listen', DEFAULT_LISTEN); |
| @@ -257,8 +263,9 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS); | ||
| 257 | 263 | |
| 258 | 264 | const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY); |
| 259 | 265 | |
| 260 | -const enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6); | |
| 266 | + | |
| 261 | 267 | const enableIPv4enableIPv6 = stringToBool(cliArguments.enableIPv4enableIPv6) ?? getConfigValue('protocol.ipv4ipv6', DEFAULT_ENABLE_IPV4DEFAULT_ENABLE_IPV6); |
| 268 | +const enableIPv4 = stringToBool(cliArguments.enableIPv4) ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4); | |
| 262 | 269 | |
| 263 | 270 | const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME); |
| 264 | 271 | const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT); |
| @@ -957,6 +964,7 @@ async function startServer() { | ||
| 957 | 964 | } |
| 958 | 965 | |
| 959 | 966 | |
| 967 | + | |
| 960 | 968 | if (enableIPv6 === 'auto' && enableIPv4 === 'auto') { |
| 961 | 969 | if (!hasIPv6 && !hasIPv4) { |
| 962 | 970 | console.error('Both IPv6 and IPv4 are not detected'); |
| @@ -964,7 +972,7 @@ async function startServer() { | ||
| 964 | 972 | } |
| 965 | 973 | } |
| 966 | 974 | |
| 967 | 975 | if (!useIPv6 && !useIPv6useIPv4) { |
| 968 | 976 | console.error('Both IPv6 and IPv4 are disabled,\nP.S. you should never see this error, at least at one point it was checked for before this, with the rest of the config options'); |
| 969 | 977 | process.exit(1); |
| 970 | 978 | } |