add pathHelper

This commit is contained in:
Sainan 2025-04-01 13:48:26 +02:00
parent 71fb01402a
commit 1b6083f901
4 changed files with 8 additions and 7 deletions

View File

@ -0,0 +1,4 @@
import path from "path";
export const rootDir = path.join(__dirname, "../..");
export const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;

View File

@ -1,9 +1,8 @@
import express from "express";
import path from "path";
import { repoDir, rootDir } from "@/src/helpers/pathHelper";
const webuiRouter = express.Router();
const rootDir = path.join(__dirname, "../..");
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
// Redirect / to /webui/
webuiRouter.get("/", (_req, res) => {

View File

@ -1,5 +1,6 @@
import path from "path";
import fs from "fs";
import { repoDir } from "@/src/helpers/pathHelper";
interface IBuildConfig {
version: string;
@ -13,8 +14,6 @@ export const buildConfig: IBuildConfig = {
matchmakingBuildId: ""
};
const rootDir = path.join(__dirname, "../..");
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
const buildConfigPath = path.join(repoDir, "static/data/buildConfig.json");
if (fs.existsSync(buildConfigPath)) {
Object.assign(buildConfig, JSON.parse(fs.readFileSync(buildConfigPath, "utf-8")) as IBuildConfig);

View File

@ -1,10 +1,9 @@
import path from "path";
import fs from "fs";
import fsPromises from "fs/promises";
import path from "path";
import { repoDir } from "@/src/helpers/pathHelper";
import { logger } from "@/src/utils/logger";
const rootDir = path.join(__dirname, "../..");
const repoDir = path.basename(rootDir) == "build" ? path.join(rootDir, "..") : rootDir;
const configPath = path.join(repoDir, "config.json");
export const config = JSON.parse(fs.readFileSync(configPath, "utf-8")) as IConfig;