From 063e7890e4f441c4261a1bce9683dae6c2a43e90 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Sat, 1 Nov 2025 20:29:28 -0700 Subject: [PATCH 1/2] Support env variables inside config variables site_name=$USER}'s event site will get pouplated by process.env.GATHIO_USER --- src/lib/config.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index d4734cf..710d41a 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -200,7 +200,12 @@ export const getConfig = (): GathioConfig => { try { const config = toml.parse( - fs.readFileSync("./config/config.toml", "utf-8"), + fs + .readFileSync("./config/config.toml", "utf-8") + .toString() + .replace(/\$\{(\w+)\}/g, (match) => { + return process.env[`GATHIO_${match.slice(2, -1)}`] || match; + }), ) as GathioConfig; const resolvedConfig = { ...defaultConfig, From 80749b1d250e2578364ce9d911dec9cd8e5f6c26 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Sat, 1 Nov 2025 20:56:10 -0700 Subject: [PATCH 2/2] Based on feedback in #219, replace variables after toml parsing --- src/lib/config.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index 710d41a..0d8eb20 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -190,6 +190,24 @@ export const instanceDescription = (): string => { } }; +const processConfigEnv = (config: GathioConfig) => { + for (const configValue of Object.values(config)) { + if (typeof configValue !== "object") continue; + for (const [subConfigKey, subConfigValue] of Object.entries(configValue)) { + if (typeof subConfigValue === "string") { + configValue[subConfigKey as keyof typeof configValue] = + subConfigValue.replace(/\$\{(\w+)\}/g, (orig, match) => { + if (!match) return orig; + if (match.startsWith("GATHIO_")) { + return process.env[match] || orig; + } + return orig; + }); + } + } + } +}; + let _resolvedConfig: GathioConfig | null = null; // Attempt to load our global config. Will stop the app if the config file // cannot be read (there's no point trying to continue!) @@ -200,13 +218,9 @@ export const getConfig = (): GathioConfig => { try { const config = toml.parse( - fs - .readFileSync("./config/config.toml", "utf-8") - .toString() - .replace(/\$\{(\w+)\}/g, (match) => { - return process.env[`GATHIO_${match.slice(2, -1)}`] || match; - }), + fs.readFileSync("./config/config.toml", "utf-8"), ) as GathioConfig; + processConfigEnv(config); const resolvedConfig = { ...defaultConfig, ...config, @@ -219,7 +233,6 @@ export const getConfig = (): GathioConfig => { "You have not configured this Gathio instance to send emails! This means that event creators will not receive emails when their events are created, which means they may end up locked out of editing events. Consider setting up an email service.", ); } - _resolvedConfig = resolvedConfig; return resolvedConfig; } catch {