0009. Runtime configuration injected into the static build (`window.VITE_APP_*`)
Generated from front/docs/adr/0009-runtime-environment-injection-into-static-build.md
- Status: Accepted (retroactive)
- Date: 2022-05-24 (first version); 2024-09-30 (current PHP-based version)
Context and Problem Statement
Section titled “Context and Problem Statement”A CRA/Vite build bakes process.env/import.meta.env values into the bundle. The demo is
shipped as one Docker image (escolalms/demo) that must point at different API URLs,
Sentry DSNs, routers and Firebase projects per deployment - and, since 2024, per domain in a
multi-tenant setup.
Considered Options
Section titled “Considered Options”Not recorded.
Decision Outcome
Section titled “Decision Outcome”Configuration is read first from window.* globals and only then from build-time env
(config/index.ts: window.VITE_APP_API_URL || import.meta.env.VITE_APP_PUBLIC_API_URL).
- 2022-05: the multi-stage
Dockerfilecopiesindex.htmltotpl.html;entrypoint.shsed-replacesAPI_URL = null-style placeholders with container env vars on start. - 2024-09: the runtime image became
php:apache;config/php/index.phpservesindex.html, insertswindow.VITE_APP_*="..."(and legacyREACT_APP_*) for every matching env var at the<!-- inject env variables -->token, supports per-domain overrides viaMULTI_DOMAINS+<DOMAIN>_VITE_APP_*vars, and adds the Sentry release fromversion.html.
Consequences
Section titled “Consequences”- Good: one image for all environments and tenants; no rebuild to change the API URL.
- Bad: config is visible in page source (fine for public keys only).
- Bad:
entrypoint.shstill runs the 2022sedreplacements althoughindex.htmlno longer contains those placeholders. Inferred: they are now no-ops.
Evidence
Section titled “Evidence”fef5aaed2022-05-24 “Update Dockerfile (#172)” -front/Dockerfile,front/entrypoint.sh(tpl.html)95408afd2022-05-25 “docker build (#175)” -front/entrypoint.sh,front/public/index.html6e58ee4b2024-09-30 “Feature/multidomain (#500)” -front/config/php/index.php,front/Dockerfile,front/entrypoint.shc6319d872024-11-06 “Feature/multidomain (#505)”;32003f172024-11-27 “Feature/mod rewrite (#515)”