diff --git a/server/database.js b/server/database.js index 582f19c29..691cb7963 100644 --- a/server/database.js +++ b/server/database.js @@ -21,7 +21,7 @@ class Database { * Boostrap database for SQLite * @type {string} */ - static templatePath = "./db/kuma.db"; + static templatePath = path.join(__dirname, "../db/kuma.db"); /** * Data Dir (Default: ./data) @@ -124,7 +124,7 @@ class Database { static dbConfig = {}; - static knexMigrationsPath = "./db/knex_migrations"; + static knexMigrationsPath = path.join(__dirname, "../db/knex_migrations"); /** * Initialize the data directory @@ -334,7 +334,7 @@ class Database { R.freeze(true); if (autoloadModels) { - await R.autoloadModels("./server/model"); + await R.autoloadModels(path.join(__dirname, "./model")); } if (dbConfig.type === "sqlite") { @@ -470,7 +470,7 @@ class Database { // Try catch anything here try { for (let i = version + 1; i <= this.latestVersion; i++) { - const sqlFile = `./db/old_migrations/patch${i}.sql`; + const sqlFile = path.join(__dirname, `../db/old_migrations/patch${i}.sql`); log.info("db", `Patching ${sqlFile}`); await Database.importSQLFile(sqlFile); log.info("db", `Patched ${sqlFile}`); @@ -629,7 +629,7 @@ class Database { log.info("db", sqlFilename + " is patching"); this.patched = true; - await this.importSQLFile("./db/old_migrations/" + sqlFilename); + await this.importSQLFile(path.join(__dirname, "../db/old_migrations/" + sqlFilename)); databasePatchedFiles[sqlFilename] = true; log.info("db", sqlFilename + " was patched successfully"); diff --git a/server/server.js b/server/server.js index 476ef644b..ba145da4a 100644 --- a/server/server.js +++ b/server/server.js @@ -36,6 +36,7 @@ if (!semver.satisfies(nodeVersion, requiredNodeVersions)) { console.warn("\x1b[31m%s\x1b[0m", `Warning: Your Node.js version: ${nodeVersion} is not officially supported, please upgrade your Node.js to ${requiredNodeVersionsComma}.`); } +const path = require("path"); const args = require("args-parser")(process.argv); const { sleep, log, getRandomInt, genSecret, isDev } = require("../src/util"); const config = require("./config"); @@ -294,7 +295,7 @@ let needSetup = false; // With Basic Auth using the first user's username/password app.get("/metrics", apiAuth, prometheusAPIMetrics()); - app.use("/", expressStaticGzip("dist", { + app.use("/", expressStaticGzip(path.join(__dirname, "../dist"), { enableBrotli: true, })); diff --git a/server/setup-database.js b/server/setup-database.js index 483f2c9a4..32e0e17ba 100644 --- a/server/setup-database.js +++ b/server/setup-database.js @@ -243,7 +243,7 @@ class SetupDatabase { }); - app.use("/", expressStaticGzip("dist", { + app.use("/", expressStaticGzip(path.join(__dirname, "../dist"), { enableBrotli: true, })); diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 1f75b72cc..aa1f76c4f 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -99,7 +99,7 @@ class UptimeKumaServer { } try { - this.indexHTML = fs.readFileSync("./dist/index.html").toString(); + this.indexHTML = fs.readFileSync(path.join(__dirname, "../dist/index.html")).toString(); } catch (e) { // "dist/index.html" is not necessary for development if (process.env.NODE_ENV !== "development") {