/** * The `NEXT_PUBLIC_*` values this app needs, read once and validated here * rather than defaulted at each use site. Mirrors `lib/env.ts` in * nachklang-feedback, nachklang-admin and nachklang-tickets. * * Throwing is the whole point. Next inlines `process.env.NEXT_PUBLIC_*` at * **build** time, so a value missing when Plesk runs `npm run build` is baked * into the bundle and cannot be fixed by restarting the app. A fallback to * localhost would ship an admin area that sends every signed-out user to * `http://localhost:3002` - no error, no log, just a dead end. A failed build is * the better outcome, on the machine that can still do something about it. * * Referenced by their full literal name because that is what the inlining * matches - no dynamic lookup, no destructuring of `process.env`. */ function requireEnv(name: string, value: string | undefined): string { if (!value) { throw new Error(`${name} is not set. Copy .env.local.example and fill it in before building.`); } // URL.origin never carries a trailing slash, and neither should anything we concatenate onto. return value.replace(/\/+$/, ""); } export const API_BASE_URL = requireEnv("NEXT_PUBLIC_API_BASE_URL", process.env.NEXT_PUBLIC_API_BASE_URL); export const ADMIN_APP_URL = requireEnv("NEXT_PUBLIC_ADMIN_APP_URL", process.env.NEXT_PUBLIC_ADMIN_APP_URL);