diff --git a/lib/admin/config-manager.ts b/lib/admin/config-manager.ts index 8146a538..f094f6a3 100644 --- a/lib/admin/config-manager.ts +++ b/lib/admin/config-manager.ts @@ -2,6 +2,7 @@ import { readFile, writeFile, mkdir, rename } from 'node:fs/promises'; import { existsSync } from 'node:fs'; import path from 'node:path'; import { logger } from '@/lib/logger'; +import { readFileEnv } from '@/lib/read-file-env'; import { CONFIG_ENV_MAP, DEFAULT_POLICY, DEFAULT_THEME_POLICY, type SettingsPolicy } from './types'; function getAdminDir(): string { @@ -64,6 +65,12 @@ class ConfigManager { if (envVal !== undefined) { return parseEnvValue(envVal, mapping.type) as T; } + if (mapping.fileEnvVar) { + const fileVal = readFileEnv(process.env[mapping.fileEnvVar]); + if (fileVal !== null) { + return parseEnvValue(fileVal, mapping.type) as T; + } + } if (defaultValue !== undefined) return defaultValue; return mapping.defaultValue as T; } @@ -94,9 +101,16 @@ class ConfigManager { const envVal = process.env[mapping.envVar]; if (envVal !== undefined) { result[key] = { value: parseEnvValue(envVal, mapping.type), source: 'env' }; - } else { - result[key] = { value: mapping.defaultValue, source: 'default' }; + continue; } + if (mapping.fileEnvVar) { + const fileVal = readFileEnv(process.env[mapping.fileEnvVar]); + if (fileVal !== null) { + result[key] = { value: parseEnvValue(fileVal, mapping.type), source: 'env' }; + continue; + } + } + result[key] = { value: mapping.defaultValue, source: 'default' }; } } return result; diff --git a/lib/admin/types.ts b/lib/admin/types.ts index 873a73fc..07171f31 100644 --- a/lib/admin/types.ts +++ b/lib/admin/types.ts @@ -106,7 +106,7 @@ export interface AuditEntry { } /** Config keys that map to environment variables */ -export const CONFIG_ENV_MAP: Record = { +export const CONFIG_ENV_MAP: Record = { appName: { envVar: 'APP_NAME', type: 'string', defaultValue: 'Webmail' }, jmapServerUrl: { envVar: 'JMAP_SERVER_URL', type: 'url', defaultValue: '' }, stalwartFeaturesEnabled: { envVar: 'STALWART_FEATURES', type: 'boolean', defaultValue: true }, @@ -124,7 +124,7 @@ export const CONFIG_ENV_MAP: Record