allow changing data dir

This commit is contained in:
LouisLam 2021-09-02 20:27:18 +08:00
parent dac410c850
commit c74986647e
2 changed files with 11 additions and 4 deletions

View File

@ -5,7 +5,8 @@ const { setSetting, setting } = require("./util-server");
class Database {
static templatePath = "./db/kuma.db"
static path = "./data/kuma.db";
static dataDir = "./data/";
static path = this.dataDir + "kuma.db";
static latestVersion = 8;
static noReject = true;
static sqliteInstance = null;
@ -56,7 +57,7 @@ class Database {
console.info("Database patch is needed")
console.info("Backup the db")
const backupPath = "./data/kuma.db.bak" + version;
const backupPath = this.dataDir + "kuma.db.bak" + version;
fs.copyFileSync(Database.path, backupPath);
const shmPath = Database.path + "-shm";

View File

@ -50,15 +50,21 @@ const port = parseInt(process.env.PORT || args.port || 3001);
const sslKey = process.env.SSL_KEY || args.ssl_key || undefined;
const sslCert = process.env.SSL_CERT || args.ssl_cert || undefined;
// Data Directory (must be end with "/")
Database.dataDir = process.env.DATA_DIR || process.env.data_dir || "./data/";
console.log(`Data Dir: ${Database.dataDir}`);
console.log("Creating express and socket.io instance")
const app = express();
let server;
if (sslKey && sslCert) {
https.createServer(app);
console.log("Server Type: HTTPS");
server = https.createServer(app);
} else {
http.createServer(app);
console.log("Server Type: HTTP");
server = http.createServer(app);
}
const io = new Server(server);