/** Fallback-Adresse des WebSocket-Servers, falls weder .env noch /api/config etwas liefern. */ export const DEFAULT_WS_HOST = '127.0.0.1' export const DEFAULT_WS_PORT = 17654 export const DEFAULT_WS_PATH = '/ws' export const DEFAULT_WS_URL = import.meta.env.VITE_WS_URL ?? `ws://${DEFAULT_WS_HOST}:${DEFAULT_WS_PORT}${DEFAULT_WS_PATH}` export interface ClientConfig { websocketUrl: string host: string port: number path: string } /** * Holt die WebSocket-Adresse vom Backend. Schlägt der Aufruf fehl (Backend nicht * erreichbar, rein statisches Hosting), bleibt es beim Default aus der .env. */ export async function fetchClientConfig(signal?: AbortSignal): Promise { const response = await fetch('/api/config', { signal }) if (!response.ok) { throw new Error(`/api/config antwortete mit HTTP ${response.status}`) } const config = (await response.json()) as Partial if (!config.websocketUrl) { throw new Error('/api/config lieferte keine websocketUrl') } return config.websocketUrl }