fix(web-app): Caddy .Env-Template-Injection für API_BASE_URL + KEYCLOAK_URL
All checks were successful
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 8m33s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m35s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 1m57s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m42s

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
Stefan Mogeritsch 2026-03-14 11:27:14 +01:00
parent 6e7e22e588
commit 0666739b8c
17 changed files with 17 additions and 11 deletions

View File

@ -1,4 +1,4 @@
{
"apiBaseUrl": "{{env `API_BASE_URL`}}",
"keycloakUrl": "{{env `KEYCLOAK_URL`}}"
"apiBaseUrl": "{{.Env.API_BASE_URL}}",
"keycloakUrl": "{{.Env.KEYCLOAK_URL}}"
}

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

View File

Before

Width:  |  Height:  |  Size: 290 KiB

After

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

View File

@ -13,24 +13,30 @@
<div class="loading">Loading...</div>
</div>
<script>
// Laufzeit-Konfiguration — kein Rebuild nötig (SSoT: .env via Nginx/Caddy oder query params)
// API_BASE_URL: Prefer explicit query param, then same-origin (Nginx proxy)
// KEYCLOAK_URL: Prefer explicit query param, then derive from window.location.hostname + port 8180
// Laufzeit-Konfiguration — kein Rebuild nötig (SSoT: .env via Caddy-Templates oder query params)
// Caddy verarbeitet index.html als text/html-Template (Standard) und ersetzt .Env-Variablen.
// Lokal (webpack-dev-server): Template-Tags bleiben Literal-Strings → startsWith('{{') Prüfung greift.
(function () {
try {
const params = new URLSearchParams(window.location.search);
// API Base URL
const apiOverride = params.get('apiBaseUrl');
// Caddy injiziert: {{.Env.API_BASE_URL}} → z.B. "https://app.mo-code.at"
const apiFromCaddy = '{{.Env.API_BASE_URL}}';
const apiOverride = params.get('apiBaseUrl');
globalThis.API_BASE_URL = apiOverride
? apiOverride.replace(/\/$/, '')
: window.location.origin.replace(/\/$/, '');
: (apiFromCaddy && !apiFromCaddy.startsWith('{{')
? apiFromCaddy.replace(/\/$/, '')
: window.location.origin.replace(/\/$/, ''));
// Keycloak URL — gleiche IP wie die App, Port 8180
const kcOverride = params.get('keycloakUrl');
// Caddy injiziert: {{.Env.KEYCLOAK_URL}} → z.B. "https://auth.mo-code.at"
const kcFromCaddy = '{{.Env.KEYCLOAK_URL}}';
const kcOverride = params.get('keycloakUrl');
globalThis.KEYCLOAK_URL = kcOverride
? kcOverride.replace(/\/$/, '')
: 'http://' + window.location.hostname + ':8180';
: (kcFromCaddy && !kcFromCaddy.startsWith('{{')
? kcFromCaddy.replace(/\/$/, '')
: 'http://' + window.location.hostname + ':8180');
} catch (e) {
globalThis.API_BASE_URL = 'http://localhost:8081';