From c74986647ef4b262fde05c7076571efd7e5496e6 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 2 Sep 2021 20:27:18 +0800 Subject: [PATCH] allow changing data dir --- server/database.js | 5 +++-- server/server.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/database.js b/server/database.js index c0a53a9b8..f9414ad1b 100644 --- a/server/database.js +++ b/server/database.js @@ -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"; diff --git a/server/server.js b/server/server.js index ecdd65025..a87f37c6d 100644 --- a/server/server.js +++ b/server/server.js @@ -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);