Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -202,6 +220,7 @@ export const getConfig = (): GathioConfig => {
const config = toml.parse(
fs.readFileSync("./config/config.toml", "utf-8"),
) as GathioConfig;
processConfigEnv(config);
const resolvedConfig = {
...defaultConfig,
...config,
Expand All @@ -214,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 {
Expand Down