summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-11 18:16:57 +0200
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-19 00:01:33 +1100
commit655ea00ff4ae89c7995572363ae286c7d04b51a3 (patch)
tree0e2edb2086e6a68b6a5b766ca1a5f01ef04dfd30 /src
parentDo the funny thing (make user->invite cascade delet) (diff)
downloadserver-655ea00ff4ae89c7995572363ae286c7d04b51a3.tar.xz
Make fosscord read config from json if CONFIG_PATH is set
Diffstat (limited to 'src')
-rw-r--r--src/util/util/Config.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts
index 7fab7f90..55d7fab1 100644
--- a/src/util/util/Config.ts
+++ b/src/util/util/Config.ts
@@ -8,7 +8,7 @@ import path from "path";
 import fs from "fs";
 
 // TODO: yaml instead of json
-// const overridePath = path.join(process.cwd(), "config.json");
+const overridePath = process.env.CONFIG_PATH ?? "";
 
 var config: ConfigValue;
 var pairs: ConfigEntity[];
@@ -23,12 +23,16 @@ export const Config = {
 		config = pairsToConfig(pairs);
 		config = (config || {}).merge(DefaultConfigOptions);
 
-		// try {
-		// 	const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" }));
-		// 	config = overrideConfig.merge(config);
-		// } catch (error) {
-		// 	fs.writeFileSync(overridePath, JSON.stringify(config, null, 4));
-		// }
+		if (process.env.CONFIG_PATH) {
+			console.log(`[Config] Using config path from environment rather than database.`);
+			try {
+				const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" }));
+				config = overrideConfig.merge(config);
+			} catch (error) {
+				fs.writeFileSync(overridePath, JSON.stringify(config, null, 4));
+			}
+		}
+
 
 		return this.set(config);
 	},
@@ -59,7 +63,9 @@ function applyConfig(val: ConfigValue) {
 		pair.value = obj;
 		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);
 }