*Setup os specific config locations

This commit is contained in:
Derrick Hammer 2022-07-22 20:27:54 -04:00
parent dc5996957e
commit f5d00640cc
1 changed files with 26 additions and 2 deletions

View File

@ -1,11 +1,33 @@
// @ts-ignore // @ts-ignore
import BConfig from "bcfg"; import BConfig from "bcfg";
import { errorExit } from "./util.js"; import { errorExit } from "./util.js";
import * as os from "os";
import { createRequire } from "module";
import path from "path";
const require = createRequire(import.meta.url);
const config = new BConfig("lumeweb-relay"); const config = new BConfig("lumeweb-relay");
let configLocation;
const configFile = "config.conf";
switch (os.platform()) {
case "win32":
configLocation = path.resolve(
require?.main?.filename as string,
configFile
);
break;
case "linux":
default:
configLocation = path.join("/etc/lumeweb/relay", configFile);
break;
}
config.inject({ config.inject({
relayPort: 8080, relayPort: 8080,
config: configLocation,
}); });
config.load({ config.load({
@ -13,8 +35,10 @@ config.load({
argv: true, argv: true,
}); });
try { try {
config.open("config.conf"); config.open(configLocation);
} catch (e) {} } catch (e) {
console.error((e as Error).message);
}
for (const setting of ["domain", "afraid-username", "seed"]) { for (const setting of ["domain", "afraid-username", "seed"]) {
if (!config.get(setting)) { if (!config.get(setting)) {