first commit
SwyxWeb: React-Frontend und Spring-Boot-Backend mit SwyxTray-Mock. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/** Fallback-Adresse des WebSocket-Servers, falls weder .env noch /api/config etwas liefern. */
|
||||
export const DEFAULT_WS_HOST = '192.168.180.135'
|
||||
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<string> {
|
||||
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<ClientConfig>
|
||||
if (!config.websocketUrl) {
|
||||
throw new Error('/api/config lieferte keine websocketUrl')
|
||||
}
|
||||
return config.websocketUrl
|
||||
}
|
||||
Reference in New Issue
Block a user