feat(config): enhance base path logic to use executable directory as fallback

This commit is contained in:
Sam Chau
2025-12-29 19:00:12 +10:30
parent 473a0cf474
commit 54e64a2ed4
2 changed files with 13 additions and 4 deletions

View File

@@ -24,8 +24,9 @@
},
"tasks": {
"dev": "APP_BASE_PATH=./dist/dev deno run -A npm:vite dev",
"build": "APP_BASE_PATH=./dist/build deno run -A npm:vite build && deno compile --no-check --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-run --target x86_64-unknown-linux-gnu --output dist/build/profilarr dist/build/mod.ts",
"preview": "PORT=6868 APP_BASE_PATH=./dist/dev ./dist/build/profilarr",
"build": "APP_BASE_PATH=./dist/build deno run -A npm:vite build && deno compile --no-check --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-run --target x86_64-unknown-linux-gnu --output dist/linux/profilarr dist/build/mod.ts",
"build:windows": "APP_BASE_PATH=./dist/build deno run -A npm:vite build && deno compile --no-check --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-run --target x86_64-pc-windows-msvc --output dist/windows/profilarr.exe dist/build/mod.ts",
"preview": "PORT=6868 APP_BASE_PATH=./dist/dev ./dist/linux/profilarr",
"format": "prettier --write .",
"lint": "prettier --check . && eslint .",
"test": "APP_BASE_PATH=./dist/test deno test src/tests --allow-read --allow-write --allow-env",

View File

@@ -9,8 +9,16 @@ class Config {
constructor() {
// Default base path logic:
// 1. Check environment variable
// 2. Fall back to /app (Docker default)
this.basePath = Deno.env.get('APP_BASE_PATH') || '/app';
// 2. Fall back to directory containing the executable
const envPath = Deno.env.get('APP_BASE_PATH');
if (envPath) {
this.basePath = envPath;
} else {
// Use the directory where the executable is located
const execPath = Deno.execPath();
const lastSlash = Math.max(execPath.lastIndexOf('/'), execPath.lastIndexOf('\\'));
this.basePath = lastSlash > 0 ? execPath.substring(0, lastSlash) : '.';
}
// Timezone configuration:
// 1. Check TZ environment variable