diff --git a/server.js b/server.js index cdef0a64b..933c10d5c 100644 --- a/server.js +++ b/server.js @@ -261,7 +261,7 @@ app.use(responseTime()); /** @type {number} */ -const server_port = cliArguments.port ?? process.env.SILLY_TAVERN_PORT ?? getConfigValue('port', DEFAULT_PORT); +const server_port = cliArguments.port ?? getConfigValue('port', DEFAULT_PORT); /** @type {boolean} */ const autorun = (cliArguments.autorun ?? getConfigValue('autorun', DEFAULT_AUTORUN)) && !cliArguments.ssl; /** @type {boolean} */ diff --git a/src/util.js b/src/util.js index 0ce6f66d4..27d6d2cf6 100644 --- a/src/util.js +++ b/src/util.js @@ -20,6 +20,14 @@ import { LOG_LEVELS } from './constants.js'; */ let CACHED_CONFIG = null; +/** + * Converts a configuration key to an environment variable key. + * @param {string} key Configuration key + * @returns {string} Environment variable key + * @example keyToEnv('extensions.models.speechToText') // 'SILLYTAVERN_EXTENSIONS_MODELS_SPEECHTOTEXT' + */ +export const keyToEnv = (key) => 'SILLYTAVERN_' + String(key).toUpperCase().replace(/\./g, '_'); + /** * Returns the config object from the config.yaml file. * @returns {object} Config object @@ -53,6 +61,10 @@ export function getConfig() { * @returns {any} Value for the given key */ export function getConfigValue(key, defaultValue = null) { + const envKey = keyToEnv(key); + if (envKey in process.env) { + return process.env[envKey]; + } const config = getConfig(); return _.get(config, key, defaultValue); }