fix issue with localdb,

rename db.js to localdb.js
add option to dynamically load db backend
This commit is contained in:
Arthur Lu 2023-10-24 19:01:53 +00:00
parent 3146ae76a6
commit cb1e3a776e
2 changed files with 10 additions and 9 deletions

View File

@ -8,11 +8,11 @@ class LocalDB {
try { try {
this.#path = path; this.#path = path;
this.#load(); this.#load();
this.pveAPI = this.getConfig().application.pveAPI; this.pveAPI = this.getGlobal().application.pveAPI;
this.pveAPIToken = this.getConfig().application.pveAPIToken; this.pveAPIToken = this.getGlobal().application.pveAPIToken;
this.listenPort = this.getConfig().application.listenPort; this.listenPort = this.getGlobal().application.listenPort;
this.hostname = this.getConfig().application.hostname; this.hostname = this.getGlobal().application.hostname;
this.domain = this.getConfig().application.domain; this.domain = this.getGlobal().application.domain;
} }
catch { catch {
console.log(`Error: ${path} was not found. Please follow the directions in the README to initialize localdb.json.`); console.log(`Error: ${path} was not found. Please follow the directions in the README to initialize localdb.json.`);

View File

@ -7,20 +7,21 @@ import morgan from "morgan";
import _package from "./package.js"; import _package from "./package.js";
import * as pve from "./pve.js"; import * as pve from "./pve.js";
import * as utils from "./utils.js"; import * as utils from "./utils.js";
import LocalDB from "./db.js";
import parseArgs from "minimist"; import parseArgs from "minimist";
global.argv = parseArgs(process.argv.slice(2), { global.argv = parseArgs(process.argv.slice(2), {
default: { default: {
package: "package.json", package: "package.json",
localdb: "config/localdb.json" db: "./localdb.js", // relative to main.js
dbconfig: "config/localdb.json"
} }
}); });
global.api = _package(global.argv.package); global.api = _package(global.argv.package);
global.pve = pve; global.pve = pve;
global.utils = utils; global.utils = utils;
global.db = new LocalDB(global.argv.localdb); const db = (await import(global.argv.db)).default;
global.db = new db(global.argv.dbconfig);
const app = express(); const app = express();
global.app = app; global.app = app;