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

@ -5,14 +5,14 @@ class LocalDB {
#path = null;
#data = null;
constructor (path) {
try {
try {
this.#path = path;
this.#load();
this.pveAPI = this.getConfig().application.pveAPI;
this.pveAPIToken = this.getConfig().application.pveAPIToken;
this.listenPort = this.getConfig().application.listenPort;
this.hostname = this.getConfig().application.hostname;
this.domain = this.getConfig().application.domain;
this.pveAPI = this.getGlobal().application.pveAPI;
this.pveAPIToken = this.getGlobal().application.pveAPIToken;
this.listenPort = this.getGlobal().application.listenPort;
this.hostname = this.getGlobal().application.hostname;
this.domain = this.getGlobal().application.domain;
}
catch {
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 * as pve from "./pve.js";
import * as utils from "./utils.js";
import LocalDB from "./db.js";
import parseArgs from "minimist";
global.argv = parseArgs(process.argv.slice(2), {
default: {
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.pve = pve;
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();
global.app = app;