summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-11 18:16:57 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-13 21:57:51 +0200
commit99c40c208296c723f5d1a89d1f6c38564bef5829 (patch)
tree955398a63a330c63a5035d8d9dbc03f508e4d422
parentDo the funny thing (make user->invite cascade delet) (diff)
downloadserver-99c40c208296c723f5d1a89d1f6c38564bef5829.tar.xz
Make fosscord read config from json if CONFIG_PATH is set
-rw-r--r--util/src/util/Config.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts
index 97a73858..925cb243 100644
--- a/util/src/util/Config.ts
+++ b/util/src/util/Config.ts
@@ -3,7 +3,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 ?? "";
 
 let config: ConfigValue;
 let pairs: ConfigEntity[];
@@ -18,12 +18,14 @@ 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)
+			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);
 	},
@@ -50,7 +52,8 @@ 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);
 }