mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@@ -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} */
|
||||
|
12
src/util.js
12
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user