*Use new config fork and load directory for configs
This commit is contained in:
parent
8d8672729e
commit
e0995be647
|
@ -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);
|
||||||
|
} catch (e) {
|
||||||
console.error((e as Error).message);
|
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`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue