2022-07-05 19:02:07 +00:00
|
|
|
// @ts-ignore
|
2022-09-21 20:00:42 +00:00
|
|
|
import Config from "@lumeweb/cfg";
|
2022-07-23 00:27:54 +00:00
|
|
|
import * as os from "os";
|
2022-09-21 20:00:42 +00:00
|
|
|
import * as fs from "fs";
|
2022-07-23 00:27:54 +00:00
|
|
|
import path from "path";
|
2022-12-19 16:44:11 +00:00
|
|
|
import log from "./log.js";
|
2022-07-05 19:02:07 +00:00
|
|
|
|
2023-04-19 03:49:34 +00:00
|
|
|
const config = new Config("lumeweb-relay", "core.confdir");
|
2022-07-05 19:02:07 +00:00
|
|
|
|
2022-08-27 01:52:19 +00:00
|
|
|
let configDir;
|
2022-07-23 00:27:54 +00:00
|
|
|
|
|
|
|
switch (os.platform()) {
|
|
|
|
case "win32":
|
2022-09-21 20:00:42 +00:00
|
|
|
configDir = path.join(
|
|
|
|
path.dirname(require?.main?.filename as string),
|
|
|
|
"config"
|
|
|
|
);
|
2022-07-23 00:27:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "linux":
|
|
|
|
default:
|
2023-04-19 00:12:01 +00:00
|
|
|
configDir = "/etc/lumeweb/relay/conf.d";
|
2022-07-23 00:27:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
config.inject({
|
2023-04-19 00:12:01 +00:00
|
|
|
"core.confdir": configDir,
|
|
|
|
"core.port": 8080,
|
2023-04-19 00:28:51 +00:00
|
|
|
"core.apport": 80,
|
2023-04-19 00:12:01 +00:00
|
|
|
"core.loglevel": "info",
|
|
|
|
"core.plugindir": path.resolve(configDir, "..", "plugins"),
|
2022-07-05 19:02:07 +00:00
|
|
|
});
|
|
|
|
|
2022-12-19 16:37:49 +00:00
|
|
|
config.load();
|
2022-09-21 20:09:34 +00:00
|
|
|
|
2023-04-19 00:12:01 +00:00
|
|
|
configDir = config.str("core.confdir");
|
2022-09-21 20:09:34 +00:00
|
|
|
|
2022-09-21 20:00:42 +00:00
|
|
|
if (fs.existsSync(configDir)) {
|
|
|
|
try {
|
|
|
|
config.openDir(configDir);
|
|
|
|
} catch (e) {
|
|
|
|
console.error((e as Error).message);
|
|
|
|
}
|
2022-07-23 00:27:54 +00:00
|
|
|
}
|
2022-07-05 19:02:07 +00:00
|
|
|
|
2022-12-19 16:37:49 +00:00
|
|
|
config.load();
|
2022-09-22 11:51:58 +00:00
|
|
|
|
2023-04-19 00:12:01 +00:00
|
|
|
log.level = config.get("core.loglevel");
|
2022-12-07 06:57:21 +00:00
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
export default config;
|