*Use new config fork and load directory for configs

This commit is contained in:
Derrick Hammer 2022-09-21 16:00:42 -04:00
parent 8d8672729e
commit e0995be647
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 15 deletions

View File

@ -2,34 +2,32 @@
//import { createRequire } from "module"; //import { createRequire } from "module";
// @ts-ignore // @ts-ignore
import BConfig from "bcfg"; import Config from "@lumeweb/cfg";
import * as os from "os"; import * as os from "os";
import * as fs from "fs";
import path from "path"; import path from "path";
import { errorExit } from "./lib/error.js"; import { errorExit } from "./lib/error.js";
const config = new BConfig("lumeweb-relay"); const config = new Config("lumeweb-relay");
let configLocation;
let configDir; let configDir;
const configFile = "config.conf";
switch (os.platform()) { switch (os.platform()) {
case "win32": case "win32":
configDir = path.dirname(require?.main?.filename as string); configDir = path.join(
configLocation = path.resolve(configDir, configFile); path.dirname(require?.main?.filename as string),
"config"
);
break; break;
case "linux": case "linux":
default: default:
configDir = "/etc/lumeweb/relay"; configDir = "/etc/lumeweb/relay/config.d";
configLocation = path.join(configDir, configFile);
break; break;
} }
config.inject({ config.inject({
port: 8080, port: 8080,
config: configLocation,
logLevel: "info", logLevel: "info",
pluginDir: path.join(configDir, "plugins"), pluginDir: path.join(configDir, "plugins"),
plugins: ["core"], plugins: ["core"],
@ -40,13 +38,15 @@ config.load({
env: true, env: true,
argv: true, argv: true,
}); });
try { if (fs.existsSync(configDir)) {
config.open(configLocation); try {
} catch (e) { config.openDir(configDir);
console.error((e as Error).message); } catch (e) {
console.error((e as Error).message);
}
} }
for (const setting of ["domain", "afraid-username", "seed"]) { for (const setting of ["domain", "seed"]) {
if (!config.get(setting)) { if (!config.get(setting)) {
errorExit(`Required config option ${setting} not set`); errorExit(`Required config option ${setting} not set`);
} }