Files
bamort/desktop/RUNTIME_CONFIG.md
Bardioc26 261a6294cb Desktop app dynamic config of API Port (#40)
* added dynamic configuration of Port in Desktop app
* added dynamic configuration of API_URL to docker deployments.

Now it works with editing only .env file.
2026-02-27 11:55:30 +01:00

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 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)

Build Process

  • 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:

    API_PORT=8185  # Change to any port you want
    
  2. 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_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