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