fix(web): SvelteKit-env via \$env/dynamic/public statt import.meta.env
Some checks are pending
CI / validate (push) Waiting to run
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:
parent
3b745836bd
commit
87a7a31ece
3 changed files with 17 additions and 8 deletions
|
|
@ -10,11 +10,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { devUser } from '$lib/auth/dev-stub.svelte.ts';
|
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 = (() => {
|
export const API_BASE = (() => {
|
||||||
if (typeof window !== 'undefined') {
|
const fromPublic = publicEnv.PUBLIC_CARDS_API_URL;
|
||||||
return import.meta.env.PUBLIC_CARDS_API_URL ?? 'http://localhost:3081';
|
if (fromPublic) return fromPublic;
|
||||||
}
|
if (typeof window !== 'undefined') return 'http://localhost:3081';
|
||||||
return process.env.CARDS_API_URL ?? 'http://localhost:3081';
|
return process.env.CARDS_API_URL ?? 'http://localhost:3081';
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ function isExpired(claims: JwtClaims): boolean {
|
||||||
return claims.exp * 1000 < Date.now();
|
return claims.exp * 1000 < Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SvelteKit-konformer ENV-Zugriff (siehe client.ts für Begründung).
|
||||||
|
import { env as publicEnv } from '$env/dynamic/public';
|
||||||
|
|
||||||
function authBaseUrl(): string {
|
function authBaseUrl(): string {
|
||||||
if (typeof import.meta !== 'undefined' && import.meta.env?.PUBLIC_MANA_AUTH_URL) {
|
return publicEnv.PUBLIC_MANA_AUTH_URL ?? 'https://auth.mana.how';
|
||||||
return import.meta.env.PUBLIC_MANA_AUTH_URL;
|
|
||||||
}
|
|
||||||
return 'https://auth.mana.how';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
|
|
|
||||||
|
|
@ -103,11 +103,15 @@ services:
|
||||||
dockerfile: apps/web/Dockerfile
|
dockerfile: apps/web/Dockerfile
|
||||||
args:
|
args:
|
||||||
NPM_AUTH_TOKEN: ${NPM_AUTH_TOKEN:?missing NPM_AUTH_TOKEN}
|
NPM_AUTH_TOKEN: ${NPM_AUTH_TOKEN:?missing NPM_AUTH_TOKEN}
|
||||||
PUBLIC_CARDS_API_URL: https://cardecky-api.mana.how
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- cards-api
|
- cards-api
|
||||||
environment:
|
environment:
|
||||||
|
# SvelteKit `$env/dynamic/public` liest zur Runtime — daher
|
||||||
|
# hier statt als Build-Arg. Wert landet im SSR-Init-Snapshot
|
||||||
|
# und in client-fetches.
|
||||||
|
PUBLIC_CARDS_API_URL: https://cardecky-api.mana.how
|
||||||
|
PUBLIC_MANA_AUTH_URL: https://auth.mana.how
|
||||||
CARDS_API_URL: https://cardecky-api.mana.how
|
CARDS_API_URL: https://cardecky-api.mana.how
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue