2022-07-24 03:16:34 +00:00
|
|
|
//const require = createRequire(import.meta.url);
|
|
|
|
//import { createRequire } from "module";
|
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import BConfig from "bcfg";
|
2022-07-23 00:27:54 +00:00
|
|
|
import * as os from "os";
|
2022-07-24 03:16:34 +00:00
|
|
|
|
2022-07-23 00:27:54 +00:00
|
|
|
import path from "path";
|
2022-07-23 00:57:12 +00:00
|
|
|
import { errorExit } from "./error.js";
|
2022-07-05 19:02:07 +00:00
|
|
|
|
|
|
|
const config = new BConfig("lumeweb-relay");
|
|
|
|
|
2022-07-23 00:27:54 +00:00
|
|
|
let configLocation;
|
2022-08-27 01:52:19 +00:00
|
|
|
let configDir;
|
2022-07-23 00:27:54 +00:00
|
|
|
const configFile = "config.conf";
|
|
|
|
|
|
|
|
switch (os.platform()) {
|
|
|
|
case "win32":
|
2022-08-27 01:52:19 +00:00
|
|
|
configDir = path.dirname(require?.main?.filename as string);
|
|
|
|
configLocation = path.resolve(configDir, configFile);
|
2022-07-23 00:27:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "linux":
|
|
|
|
default:
|
2022-08-27 01:52:19 +00:00
|
|
|
configDir = "/etc/lumeweb/relay";
|
|
|
|
configLocation = path.join(configDir, configFile);
|
2022-07-23 00:27:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
config.inject({
|
2022-07-26 00:18:31 +00:00
|
|
|
port: 8080,
|
2022-07-23 00:27:54 +00:00
|
|
|
config: configLocation,
|
2022-07-24 00:24:19 +00:00
|
|
|
logLevel: "info",
|
2022-09-20 10:35:32 +00:00
|
|
|
pluginDir: path.join(configDir, "plugins"),
|
2022-08-27 01:52:19 +00:00
|
|
|
plugins: ["core"],
|
2022-09-09 09:17:25 +00:00
|
|
|
ssl: true,
|
2022-07-05 19:02:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
config.load({
|
2022-07-19 22:31:15 +00:00
|
|
|
env: true,
|
|
|
|
argv: true,
|
2022-07-05 19:02:07 +00:00
|
|
|
});
|
|
|
|
try {
|
2022-07-23 00:27:54 +00:00
|
|
|
config.open(configLocation);
|
|
|
|
} catch (e) {
|
|
|
|
console.error((e as Error).message);
|
|
|
|
}
|
2022-07-05 19:02:07 +00:00
|
|
|
|
2022-07-22 23:55:09 +00:00
|
|
|
for (const setting of ["domain", "afraid-username", "seed"]) {
|
2022-07-19 22:31:15 +00:00
|
|
|
if (!config.get(setting)) {
|
|
|
|
errorExit(`Required config option ${setting} not set`);
|
|
|
|
}
|
2022-07-05 19:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let usingPocketGateway = true;
|
|
|
|
|
|
|
|
export function usePocketGateway() {
|
2022-07-19 22:31:15 +00:00
|
|
|
return usingPocketGateway;
|
2022-07-05 19:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function updateUsePocketGateway(state: boolean): void {
|
2022-07-19 22:31:15 +00:00
|
|
|
usingPocketGateway = state;
|
2022-07-05 19:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default config;
|