fix(admin-ui): SSR sees ERROR_REPORTING_ADMIN_API_BASE at runtime
Next build inlines bare process.env.* as undefined without .env at build time. Use Reflect.get for admin API base and demo flag; add .env.production default for LXC.
This commit is contained in:
1 parent
0a8918ed00
commit
c899cef6e1
3 files changed
+12
-2
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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<string | undefined> {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user