2.2 KiB
2.2 KiB
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: The
App.GetAPIBaseURL()method reads the configured port fromconfig.Cfgand 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: Detects if running in Wails and calls the Go backend to get the API URL at runtime
- 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: The
build:desktopscript no longer hardcodesVITE_API_URL - The frontend bundle is now port-agnostic
Usage
Change the API Port
-
Edit
desktop/.env:API_PORT=8185 # Change to any port you want -
Run the app - no rebuild needed!
./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_URLfrom 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:
- Frontend makes API request
- Axios interceptor checks if
baseURLis set - If not set, calls
getAPIBaseURL()from config.js - Config.js detects Wails environment via
window.go - Calls Go backend's
GetAPIBaseURL()method - Caches the result for subsequent requests
- Request proceeds with correct baseURL