From f5d00640cc571457f13f8138ce26b6f8be657cea Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 22 Jul 2022 20:27:54 -0400 Subject: [PATCH] *Setup os specific config locations --- src/config.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index a7be0a9..4ee49df 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,11 +1,33 @@ // @ts-ignore import BConfig from "bcfg"; 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"); +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({ relayPort: 8080, + config: configLocation, }); config.load({ @@ -13,8 +35,10 @@ config.load({ argv: true, }); try { - config.open("config.conf"); -} catch (e) {} + config.open(configLocation); +} catch (e) { + console.error((e as Error).message); +} for (const setting of ["domain", "afraid-username", "seed"]) { if (!config.get(setting)) {