Split up listen address configuration between IPv4 and IPv6
Signed| @@ -7,7 +7,8 @@ cardsCacheCapacity: 100 | ||
| 7 | 7 | # Listen for incoming connections |
| 8 | 8 | listen: false |
| 9 | 9 | # Listen on a specific address, supports IPv4 and IPv6 |
| 10 | -listenAddress: 0.0.0.0 | |
| 10 | +listenAddressIPv6: [::] | |
| 11 | +listenAddressIPv4: 0.0.0.0 | |
| 11 | 12 | # Enables IPv6 and/or IPv4 protocols. Need to have at least one enabled! |
| 12 | 13 | # - Use option "auto" to automatically detect support |
| 13 | 14 | # - Use true or false (no qoutes) to enable or disable each protocol |
| @@ -131,7 +131,8 @@ if (process.versions && process.versions.node && process.versions.node.match(/20 | ||
| 131 | 131 | const DEFAULT_PORT = 8000; |
| 132 | 132 | const DEFAULT_AUTORUN = false; |
| 133 | 133 | const DEFAULT_LISTEN = false; |
| 134 | 134 | const DEFAULT_LISTEN_ADDRESSDEFAULT_LISTEN_ADDRESS_IPV6 = '[::]'; |
| 135 | +const DEFAULT_LISTEN_ADDRESS_IPV4 = '0.0.0.0'; | |
| 135 | 136 | const DEFAULT_CORS_PROXY = false; |
| 136 | 137 | const DEFAULT_WHITELIST = true; |
| 137 | 138 | const DEFAULT_ACCOUNTS = false; |
| @@ -187,10 +188,14 @@ const cliArguments = yargs(hideBin(process.argv)) | ||
| 187 | 188 | type: 'boolean', |
| 188 | 189 | default: null, |
| 189 | 190 | describe: `SillyTavern is listening on all network interfaces (Wi-Fi, LAN, localhost). If false, will limit it only to internal localhost (127.0.0.1).\nIf not provided falls back to yaml config 'listen'.\n[config default: ${DEFAULT_LISTEN}]`, |
| 190 | 191 | }).option('listenAddresslistenAddressIPv6', { |
| 191 | 192 | type: 'string', |
| 192 | 193 | default: null, |
| 193 | 194 | describe: 'Set SillyTavern to listen to a specific IPv6 address. If not set, it will fallback to listen to all.\n[config default: empty[::] ]', |
| 195 | + }).option('listenAddressIPv4', { | |
| 196 | + type: 'string', | |
| 197 | + default: null, | |
| 198 | + describe: 'Set SillyTavern to listen to a specific IPv4 address. If not set, it will fallback to listen to all.\n[config default: 0.0.0.0 ]', | |
| 194 | 199 | }).option('corsProxy', { |
| 195 | 200 | type: 'boolean', |
| 196 | 201 | default: null, |
| @@ -261,7 +266,9 @@ const autorun = (cliArguments.autorun ?? getConfigValue('autorun', DEFAULT_AUTOR | ||
| 261 | 266 | /** @type {boolean} */ |
| 262 | 267 | const listen = cliArguments.listen ?? getConfigValue('listen', DEFAULT_LISTEN); |
| 263 | 268 | /** @type {string} */ |
| 264 | 269 | const listenAddresslistenAddressIPv6 = cliArguments.listenAddresslistenAddressIPv6 ?? getConfigValue('listenAddresslistenAddressIPv6', DEFAULT_LISTEN_ADDRESSDEFAULT_LISTEN_ADDRESS_IPV6); |
| 270 | +/** @type {string} */ | |
| 271 | +const listenAddressIPv4 = cliArguments.listenAddressIPv4 ?? getConfigValue('listenAddressIPv4', DEFAULT_LISTEN_ADDRESS_IPV4); | |
| 265 | 272 | /** @type {boolean} */ |
| 266 | 273 | const enableCorsProxy = cliArguments.corsProxy ?? getConfigValue('enableCorsProxy', DEFAULT_CORS_PROXY); |
| 267 | 274 | const enableWhitelist = cliArguments.whitelist ?? getConfigValue('whitelistMode', DEFAULT_WHITELIST); |
| @@ -716,13 +723,13 @@ app.use('/api/azure', azureRouter); | ||
| 716 | 723 | |
| 717 | 724 | const tavernUrlV6 = new URL( |
| 718 | 725 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 719 | 726 | (listen ? (ipRegex.v6({ exact: true }).test(listenAddresslistenAddressIPv6) ? `[${listenAddress}]`listenAddressIPv6 : '[::]') : '[::1]') + |
| 720 | 727 | (':' + server_port), |
| 721 | 728 | ); |
| 722 | 729 | |
| 723 | 730 | const tavernUrl = new URL( |
| 724 | 731 | (cliArguments.ssl ? 'https://' : 'http://') + |
| 725 | 732 | (listen ? (ipRegex.v4({ exact: true }).test(listenAddresslistenAddressIPv4) ? listenAddresslistenAddressIPv4 : '0.0.0.0') : '127.0.0.1') + |
| 726 | 733 | (':' + server_port), |
| 727 | 734 | ); |
| 728 | 735 | |
| @@ -789,10 +796,10 @@ const preSetupTasks = async function () { | ||
| 789 | 796 | async function getAutorunHostname(useIPv6, useIPv4) { |
| 790 | 797 | if (autorunHostname === 'auto') { |
| 791 | 798 | if (listen) { |
| 792 | 799 | if (ipRegex.v4v6({ exact: true }).test(listenAddresslistenAddressIPv6)) { |
| 793 | 800 | return listenAddresslistenAddressIPv6; |
| 794 | 801 | } else if (ipRegex.v6v4({ exact: true }).test(listenAddresslistenAddressIPv4)) { |
| 795 | - return `[${listenAddress}]`; | |
| 802 | + return listenAddressIPv4; | |
| 796 | 803 | } |
| 797 | 804 | } |
| 798 | 805 | |
| @@ -858,13 +865,13 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) { | ||
| 858 | 865 | console.log('\n' + getSeparator(plainGoToLog.length) + '\n'); |
| 859 | 866 | |
| 860 | 867 | if (listen) { |
| 861 | 868 | if (ipRegex.v4v6({ exact: true }).test(listenAddresslistenAddressIPv6)) { |
| 862 | 869 | console.log( |
| 863 | 870 | `SillyTavern is listening on the address ${listenAddresslistenAddressIPv6}. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, |
| 864 | 871 | ); |
| 865 | 872 | } else if (ipRegex.v6v4({ exact: true }).test(listenAddresslistenAddressIPv4)) { |
| 866 | 873 | console.log( |
| 867 | 874 | `SillyTavern is listening on the address [${listenAddresslistenAddressIPv4}]. If you want to limit it only to internal localhost ([::1] or 127.0.0.1), change the setting in config.yaml to "listen: false". Check "access.log" file in the SillyTavern directory if you want to inspect incoming connections.\n`, |
| 868 | 875 | ); |
| 869 | 876 | } else { |
| 870 | 877 | console.log( |