fix(web-app): SW-Bypass für config.json + globalThis-Fallback in Config.kt
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 9m5s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m47s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 2m50s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m54s

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-03-14 12:34:34 +01:00
parent 0666739b8c
commit 3f9b63466c
5 changed files with 16 additions and 6 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

@@ -11,17 +11,27 @@ data class AppConfig(
suspend fun loadAppConfig(): AppConfig { suspend fun loadAppConfig(): AppConfig {
return try { return try {
// Fetch config.json generated by Caddy templates // ?_nocache erzwingt einen SW-bypassing Request (SW sieht andere URL → Cache-Miss → Netzwerk)
val response = window.fetch("/config.json").await() val response = window.fetch("/config.json?_nocache=1").await()
if (!response.ok) { if (!response.ok) {
console.warn("[Config] Failed to load config.json, falling back to defaults") console.warn("[Config] Failed to load config.json, falling back to globalThis")
return AppConfig(apiBaseUrl = window.location.origin) return fallbackFromGlobal()
} }
val text = response.text().await() val text = response.text().await()
Json.decodeFromString(AppConfig.serializer(), text) Json.decodeFromString(AppConfig.serializer(), text)
} catch (e: dynamic) { } catch (e: dynamic) {
console.error("[Config] Error loading config:", e) console.error("[Config] Error loading config:", e)
// Fallback for local development if file is missing // Fallback: Caddy-injizierte Werte aus index.html (globalThis.API_BASE_URL / KEYCLOAK_URL)
AppConfig(apiBaseUrl = "http://localhost:8081") fallbackFromGlobal()
} }
} }
private fun fallbackFromGlobal(): AppConfig {
val apiBase = (js("globalThis.API_BASE_URL") as? String)
?.takeIf { it.isNotBlank() && !it.startsWith("{{") }
?: window.location.origin
val kcUrl = (js("globalThis.KEYCLOAK_URL") as? String)
?.takeIf { it.isNotBlank() && !it.startsWith("{{") }
console.log("[Config] Fallback: apiBaseUrl=$apiBase, keycloakUrl=$kcUrl")
return AppConfig(apiBaseUrl = apiBase, keycloakUrl = kcUrl)
}