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-07 05:46:16 +00:00
|
|
|
import log from "loglevel";
|
2022-07-05 19:02:07 +00:00
|
|
|
|
2022-09-21 20:00:42 +00:00
|
|
|
const config = new Config("lumeweb-relay");
|
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:
|
2022-09-21 20:00:42 +00:00
|
|
|
configDir = "/etc/lumeweb/relay/config.d";
|
2022-07-23 00:27:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
config.inject({
|
2022-09-21 20:09:34 +00:00
|
|
|
configDir,
|
2022-07-26 00:18:31 +00:00
|
|
|
port: 8080,
|
2022-07-24 00:24:19 +00:00
|
|
|
logLevel: "info",
|
2022-09-21 21:40:17 +00:00
|
|
|
pluginDir: path.resolve(configDir, "..", "plugins"),
|
2022-08-27 01:52:19 +00:00
|
|
|
plugins: ["core"],
|
2022-09-22 12:00:02 +00:00
|
|
|
ssl: false,
|
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
|
|
|
});
|
2022-09-21 20:09:34 +00:00
|
|
|
|
|
|
|
configDir = config.str("configdir");
|
|
|
|
|
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-09-22 11:51:58 +00:00
|
|
|
config.load({
|
|
|
|
env: true,
|
|
|
|
argv: true,
|
|
|
|
});
|
|
|
|
|
2022-12-07 05:46:16 +00:00
|
|
|
log.setDefaultLevel(config.get("loglevel"));
|
|
|
|
|
2022-07-05 19:02:07 +00:00
|
|
|
export default config;
|