# Desktop Runtime Configuration The BaMoRT desktop app now uses **runtime configuration** for the API port, meaning you can change the port in the `.env` file without rebuilding the app. ## How It Works ### Backend (Go) - **[desktop/main.go](desktop/main.go)**: The `App.GetAPIBaseURL()` method reads the configured port from `config.Cfg` and returns the full API URL - This method is bound to the frontend via Wails, making it callable from JavaScript ### Frontend (Vue/JS) - **[frontend/src/utils/config.js](frontend/src/utils/config.js)**: Detects if running in Wails and calls the Go backend to get the API URL at runtime - **[frontend/src/utils/api.js](frontend/src/utils/api.js)**: Uses the dynamic config instead of a hardcoded VITE_API_URL - The API URL is cached after first retrieval for performance ### Build Process - **[frontend/package.json](frontend/package.json)**: The `build:desktop` script no longer hardcodes `VITE_API_URL` - The frontend bundle is now port-agnostic ## Usage ### Change the API Port 1. Edit `desktop/.env`: ```env API_PORT=8185 # Change to any port you want ``` 2. Run the app - no rebuild needed! ```bash ./desktop/build/bin/bamort ``` The frontend will automatically connect to the configured port. ### Environment Detection The config system automatically detects the environment: - **Desktop (Wails)**: Calls `window.go.main.App.GetAPIBaseURL()` to get the URL from Go backend - **Web (Development)**: Uses `import.meta.env.VITE_API_URL` from Vite - **Web (Production)**: Defaults to `https://bamort-api.trokan.de` ## Fallback Behavior If the desktop app can't reach the Go backend (shouldn't happen), it falls back to `http://localhost:8185`. ## Benefits ✅ Change API port without rebuilding ✅ Faster iteration during development ✅ Same binary works with different configurations ✅ Cleaner separation of config from code ## Technical Details **Request Flow:** 1. Frontend makes API request 2. Axios interceptor checks if `baseURL` is set 3. If not set, calls `getAPIBaseURL()` from config.js 4. Config.js detects Wails environment via `window.go` 5. Calls Go backend's `GetAPIBaseURL()` method 6. Caches the result for subsequent requests 7. Request proceeds with correct baseURL