From 54e64a2ed432be9e57e24eb20ea16669722f1c7c Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Mon, 29 Dec 2025 19:00:12 +1030 Subject: [PATCH] feat(config): enhance base path logic to use executable directory as fallback --- deno.json | 5 +++-- src/lib/server/utils/config/config.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/deno.json b/deno.json index 92775bd..6f28599 100644 --- a/deno.json +++ b/deno.json @@ -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", diff --git a/src/lib/server/utils/config/config.ts b/src/lib/server/utils/config/config.ts index 860b538..e68a5ab 100644 --- a/src/lib/server/utils/config/config.ts +++ b/src/lib/server/utils/config/config.ts @@ -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