summary refs log tree commit diff
path: root/util/src/util/Config.ts
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-11 23:11:48 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-13 21:57:51 +0200
commit34ca1a8a6c1b195c45f13ebd3b29064a9623af6f (patch)
tree26314ecd6bf95d5f8783744340e30fa0cdfc2811 /util/src/util/Config.ts
parentMake fosscord read config from json if CONFIG_PATH is set (diff)
downloadserver-34ca1a8a6c1b195c45f13ebd3b29064a9623af6f.tar.xz
Make ConfigValue a directory, move defaults to those classes instead of a separate object
Diffstat (limited to '')
-rw-r--r--util/src/util/Config.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts

index 925cb243..0b55ca4b 100644 --- a/util/src/util/Config.ts +++ b/util/src/util/Config.ts
@@ -1,6 +1,7 @@ -import { ConfigValue, ConfigEntity, DefaultConfigOptions } from "../entities/Config"; -import path from "path"; +import { ConfigEntity } from "../entities/Config"; import fs from "fs"; +import { ConfigValue } from "../config"; +import { OrmUtils } from "."; // TODO: yaml instead of json const overridePath = process.env.CONFIG_PATH ?? ""; @@ -14,9 +15,11 @@ let pairs: ConfigEntity[]; export const Config = { init: async function init() { if (config) return config; + console.log('[Config] Loading configuration...') pairs = await ConfigEntity.find(); config = pairsToConfig(pairs); - config = (config || {}).merge(DefaultConfigOptions); + //config = (config || {}).merge(new ConfigValue()); + config = OrmUtils.mergeDeep(new ConfigValue(), config) if(process.env.CONFIG_PATH) try { @@ -30,6 +33,11 @@ export const Config = { return this.set(config); }, get: function get() { + if(!config) { + if(/--debug|--inspect/.test(process.execArgv.join(' '))) + console.log("Oops.. trying to get config without config existing... Returning defaults... (Is the database still initialising?)"); + return new ConfigValue(); + } return config; }, set: function set(val: Partial<ConfigValue>) {