2.0 KiB
2.0 KiB
0065 One API end point per side
Status: Superseded by 0066 · Area: architecture · Date: 2026-10-16 · Decided by: user · Supersedes: 0018
Context
The server's API address was an env value (API_INTERNAL_ORIGIN, ADMIN_API_INTERNAL_ORIGIN in the admin app) and the browser's was a constant (API_PROXY_PATH = '/api'). The user wants both as env values with the same keys in every app, set in the bootstraps.
Decision
- Every app's env has
INTERNAL_END_POINT(server only) andNEXT_PUBLIC_CLIENT_END_POINT(public), with the same names in bull, bear and wall-street-plaza. INTERNAL_END_POINTis the API's origin from inside the deployment network (the gateway, or admin-api in the admin app). The server bootstrap's HTTP client calls it directly and sends no session cookies.NEXT_PUBLIC_CLIENT_END_POINTis a path on the app's own origin (/api), never another origin. The client bootstrap's HTTP client and the platform'sapiBaseUrl(media URLs) use it, and each app'snext.config.tsrewrites<path>/:path*toINTERNAL_END_POINT.- The gateway still scopes the refresh cookie to
/api/v1/auth(AUTH_COOKIE_PATH_PREFIX=/api) and keeps the apps' origins inCORS_ORIGINS.
Alternatives
- A constant
/apifor the browser (0018): replaced, the user wants both sides set by env. - A full URL for the browser end point: not chosen; cross-origin calls bring back CORS and API-host cookies (0018's context). The env lib's
sitePathrejects an origin.
Consequences
next buildfixes the rewrite, so each environment's build needs both values;SKIP_ENV_VALIDATIONcan't skip them, and a build without them fails.- Changing
NEXT_PUBLIC_CLIENT_END_POINTfrom/apialso needs the gateway'sAUTH_COOKIE_PATH_PREFIXchanged, or the refresh cookie never reaches the refresh call. - 0018's proxy consequences still hold: API traffic passes through the Next.js server (
API_PROXY_TIMEOUT_MS), and the client IP comes from the edge'sX-Forwarded-For.