Switch runtime config handling to JSON-based Caddy templates in frontend.
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 8m37s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m28s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 2m1s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m53s
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 8m37s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m28s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 2m1s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m53s
This commit is contained in:
@@ -12,16 +12,28 @@
|
|||||||
<div id="ComposeTarget">
|
<div id="ComposeTarget">
|
||||||
<div class="loading">Loading...</div>
|
<div class="loading">Loading...</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Schritt 1: Caddy füllt dieses JSON-Template aus.
|
||||||
|
Der Inhalt ist reines JSON, was Syntaxkonflikte mit JS vermeidet.
|
||||||
|
-->
|
||||||
|
<script id="app-config" type="application/json">
|
||||||
|
{
|
||||||
|
"apiBaseUrl": "{{.Env.API_BASE_URL}}",
|
||||||
|
"keycloakUrl": "{{.Env.KEYCLOAK_URL}}"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Laufzeit-Konfiguration — kein Rebuild nötig (SSoT: .env via Caddy-Templates oder query params)
|
// Schritt 2: Das Haupt-Skript liest die Konfiguration aus dem JSON-Block.
|
||||||
// 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 () {
|
(function () {
|
||||||
try {
|
try {
|
||||||
|
const configElement = document.getElementById('app-config');
|
||||||
|
const configJson = configElement.textContent || '{}';
|
||||||
|
const config = JSON.parse(configJson);
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
// Caddy injiziert: {{.Env.API_BASE_URL}} → z.B. "https://app.mo-code.at"
|
const apiFromCaddy = config.apiBaseUrl;
|
||||||
const apiFromCaddy = `{{.Env.API_BASE_URL}}`;
|
|
||||||
const apiOverride = params.get('apiBaseUrl');
|
const apiOverride = params.get('apiBaseUrl');
|
||||||
globalThis.API_BASE_URL = apiOverride
|
globalThis.API_BASE_URL = apiOverride
|
||||||
? apiOverride.replace(/\/$/, '')
|
? apiOverride.replace(/\/$/, '')
|
||||||
@@ -29,8 +41,7 @@
|
|||||||
? apiFromCaddy.replace(/\/$/, '')
|
? apiFromCaddy.replace(/\/$/, '')
|
||||||
: 'http://' + window.location.origin.replace(/\/$/, ''));
|
: 'http://' + window.location.origin.replace(/\/$/, ''));
|
||||||
|
|
||||||
// Caddy injiziert: {{.Env.KEYCLOAK_URL}} → z.B. "https://auth.mo-code.at"
|
const kcFromCaddy = config.keycloakUrl;
|
||||||
const kcFromCaddy = `{{.Env.KEYCLOAK_URL}}`;
|
|
||||||
const kcOverride = params.get('keycloakUrl');
|
const kcOverride = params.get('keycloakUrl');
|
||||||
globalThis.KEYCLOAK_URL = kcOverride
|
globalThis.KEYCLOAK_URL = kcOverride
|
||||||
? kcOverride.replace(/\/$/, '')
|
? kcOverride.replace(/\/$/, '')
|
||||||
@@ -39,12 +50,14 @@
|
|||||||
: 'http://' + window.location.hostname + ':8180');
|
: 'http://' + window.location.hostname + ':8180');
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error('Error loading runtime configuration:', e);
|
||||||
globalThis.API_BASE_URL = 'http://localhost:8081';
|
globalThis.API_BASE_URL = 'http://localhost:8081';
|
||||||
globalThis.KEYCLOAK_URL = 'http://localhost:8180';
|
globalThis.KEYCLOAK_URL = 'http://localhost:8180';
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
// KMP bundle liest globalThis.API_BASE_URL und globalThis.KEYCLOAK_URL in PlatformConfig.js
|
// KMP bundle liest globalThis.API_BASE_URL und globalThis.KEYCLOAK_URL in PlatformConfig.js
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="web-app.js"></script>
|
<script src="web-app.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// Register Service Worker only in non-localhost environments
|
// Register Service Worker only in non-localhost environments
|
||||||
|
|||||||
Reference in New Issue
Block a user