Make fosscord read config from json if CONFIG_PATH is set

This commit is contained in:
TheArcaneBrony 2022-08-11 18:16:57 +02:00 committed by Madeline
parent 5e4bbc2e83
commit 655ea00ff4

View File

@ -8,7 +8,7 @@ import path from "path";
import fs from "fs"; import fs from "fs";
// TODO: yaml instead of json // TODO: yaml instead of json
// const overridePath = path.join(process.cwd(), "config.json"); const overridePath = process.env.CONFIG_PATH ?? "";
var config: ConfigValue; var config: ConfigValue;
var pairs: ConfigEntity[]; var pairs: ConfigEntity[];
@ -23,12 +23,16 @@ export const Config = {
config = pairsToConfig(pairs); config = pairsToConfig(pairs);
config = (config || {}).merge(DefaultConfigOptions); config = (config || {}).merge(DefaultConfigOptions);
// try { if (process.env.CONFIG_PATH) {
// const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" })); console.log(`[Config] Using config path from environment rather than database.`);
// config = overrideConfig.merge(config); try {
// } catch (error) { const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" }));
// fs.writeFileSync(overridePath, JSON.stringify(config, null, 4)); config = overrideConfig.merge(config);
// } } catch (error) {
fs.writeFileSync(overridePath, JSON.stringify(config, null, 4));
}
}
return this.set(config); return this.set(config);
}, },
@ -59,7 +63,9 @@ function applyConfig(val: ConfigValue) {
pair.value = obj; pair.value = obj;
return pair.save(); return pair.save();
} }
// fs.writeFileSync(overridePath, JSON.stringify(val, null, 4));
if (process.env.CONFIG_PATH)
fs.writeFileSync(overridePath, JSON.stringify(val, null, 4));
return apply(val); return apply(val);
} }