diff --git a/admin-ui/.env.example b/admin-ui/.env.example index dc6b9a7..5582280 100644 --- a/admin-ui/.env.example +++ b/admin-ui/.env.example @@ -1,4 +1,6 @@ # URL base da API para dados no servidor (SSR). Sem trailing slash. +# Em produção o ficheiro `.env.production` no mesmo directório define o default para o build; +# systemd pode também exportar a mesma variável em runtime. # ERROR_REPORTING_ADMIN_API_BASE=http://127.0.0.1:3200 # Origem opcional para pedidos de login no browser; por omissão usa o hostname actual. diff --git a/admin-ui/.env.production b/admin-ui/.env.production new file mode 100644 index 0000000..73c99c0 --- /dev/null +++ b/admin-ui/.env.production @@ -0,0 +1,2 @@ +# Lido em `next build` e em runtime (SSR). URL interna da API admin no CT único. +ERROR_REPORTING_ADMIN_API_BASE=http://127.0.0.1:3200 diff --git a/admin-ui/lib/incidents-data.ts b/admin-ui/lib/incidents-data.ts index 3167afe..bcaaf67 100644 --- a/admin-ui/lib/incidents-data.ts +++ b/admin-ui/lib/incidents-data.ts @@ -2,11 +2,17 @@ import { cookies } from "next/headers"; import { getDemoIncidentDetail, getDemoIncidentSummaries } from "./demo-incidents"; import type { DetailResult, IncidentState, IncidentSummary, ListResult, Severity } from "./types"; +/** Read env at runtime — avoid `process.env.FOO` here or `next build` may inline undefined. */ +function _envStr(key: string): string | undefined { + const v = Reflect.get(process.env, key); + return typeof v === "string" ? v : undefined; +} + function _isDemoEnabled(): boolean { if (process.env.NODE_ENV === "production") { return false; } - return process.env.ERROR_REPORTING_UI_DEMO === "1"; + return _envStr("ERROR_REPORTING_UI_DEMO") === "1"; } /** Forward session cookie to internal admin API (SSR fetch). */ @@ -24,7 +30,7 @@ async function _sessionCookieHeader(): Promise { } function _apiBase(): string | null { - const _raw = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim(); + const _raw = _envStr("ERROR_REPORTING_ADMIN_API_BASE")?.trim(); if (!_raw) { return null; }