fix(web): SvelteKit-env via \$env/dynamic/public statt import.meta.env
Some checks are pending
CI / validate (push) Waiting to run

Bug: Browser-Client requested localhost:3081 statt cardecky-api.mana.how
nach Login. Ursache: API_BASE und authBaseUrl() lasen die Variable
über import.meta.env.PUBLIC_*, was unter SvelteKit nicht zuverlässig
inlined wird (Vite-direct, ohne SvelteKit-Wrapper-Hook).

Fix: \$env/dynamic/public liest die env zur Runtime aus den Node-
Server-Variablen (adapter-node) — Browser bekommt sie über den
SSR-Init-Snapshot. Damit muss die Variable nur als runtime-env am
Container hängen, nicht als Build-Arg.

docker-compose.production.yml: PUBLIC_CARDS_API_URL und
PUBLIC_MANA_AUTH_URL aus build.args nach environment verschoben.
Build-Pipeline: cards-web muss neu gebaut werden, sonst greift der
Wechsel von static→dynamic env nicht.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-05-08 22:03:35 +02:00
parent 3b745836bd
commit 87a7a31ece
3 changed files with 17 additions and 8 deletions

View file

@ -10,11 +10,16 @@
*/
import { devUser } from '$lib/auth/dev-stub.svelte.ts';
import { env as publicEnv } from '$env/dynamic/public';
// `$env/dynamic/public` liest die env zur Runtime aus den ENV-Vars
// des Node-Servers (adapter-node). Im Browser kommt der Wert aus dem
// vom Server gerenderten Init-Snapshot, daher gleicher Pfad für SSR
// und Client. Falls nichts gesetzt → localhost:3081 (Dev-Default).
export const API_BASE = (() => {
if (typeof window !== 'undefined') {
return import.meta.env.PUBLIC_CARDS_API_URL ?? 'http://localhost:3081';
}
const fromPublic = publicEnv.PUBLIC_CARDS_API_URL;
if (fromPublic) return fromPublic;
if (typeof window !== 'undefined') return 'http://localhost:3081';
return process.env.CARDS_API_URL ?? 'http://localhost:3081';
})();