feat(portal-shell): wire environment.ts per ADR-0018 #90

Merged
julien merged 1 commits from feat/portal-shell/environment-ts-wiring into main 2026-05-11 12:48:56 +02:00
Owner

Summary

First implementation step of ADR-0018. Create src/environments/environment.ts holding the two SPA per-environment values the ADR calls out — bffApiBaseUrl and otlpEndpoint — and replace the hard-coded URLs at the two SPA call sites that needed them.

What changes

  • New environment.ts with dev defaults (http://localhost:3000/api and http://localhost:4318/v1/traces). Header comment links to ADR-0018, documents the constraint that per-environment siblings must share the same shape, and notes that nothing here is a secret (the SPA bundle is public).
  • observability/tracing.ts reads environment.otlpEndpoint for the exporter, and derives the propagateTraceHeaderCorsUrls regex from environment.bffApiBaseUrl — a future change to the BFF origin propagates traceparent to the right host automatically, no second edit needed.
  • home-status.service.ts builds /health as ${environment.bffApiBaseUrl}/health.

What this PR explicitly does NOT do

  • No environment.staging.ts / environment.prod.ts yet. The ADR says "ship later" for those, and the real prod / staging URLs are unknown until the infrastructure ADR lands. Dropping plausible-but-wrong URLs into the repo would be worse than waiting.
  • No fileReplacements configuration in project.json — it depends on the per-environment files existing. Wired in the same PR that introduces them.
  • No BFF-side audit pool split (AUDIT_DATABASE_URL validator, second Prisma client, boot-time UPDATE-rejection self-test). Also in the ADR's Confirmation list, but it touches AuditModule and deserves its own review. Separate PR.
  • No SERVICE_VERSION wiring in tracing.ts. Still hard-coded to 'dev'; the build-time version source (same one that will feed the footer's dev-only version badge) is its own small chantier.

Test plan

  • pnpm exec nx run-many -t lint test build --projects=portal-shell — green (36 / 36 specs unchanged, no new tests needed).
  • Production build size unchanged (121 kB gzip initial — environment.ts is one literal object inlined by the bundler).
  • Manual: pnpm exec nx serve portal-shell → home page loads, the health widget hits the BFF, Jaeger shows the SPA document_load + fetch + BFF child span trace.
  • Manual: temporarily change bffApiBaseUrl to http://localhost:9999/api → the fetch fails (expected), and the traceparent propagation regex no longer matches :3000 (verifiable in Network panel — header is absent on cross-origin requests).
## Summary First implementation step of ADR-0018. Create [`src/environments/environment.ts`](apps/portal-shell/src/environments/environment.ts) holding the two SPA per-environment values the ADR calls out — `bffApiBaseUrl` and `otlpEndpoint` — and replace the hard-coded URLs at the two SPA call sites that needed them. ## What changes - **New `environment.ts`** with dev defaults (`http://localhost:3000/api` and `http://localhost:4318/v1/traces`). Header comment links to ADR-0018, documents the constraint that per-environment siblings must share the same shape, and notes that nothing here is a secret (the SPA bundle is public). - **`observability/tracing.ts`** reads `environment.otlpEndpoint` for the exporter, and **derives** the `propagateTraceHeaderCorsUrls` regex from `environment.bffApiBaseUrl` — a future change to the BFF origin propagates `traceparent` to the right host automatically, no second edit needed. - **`home-status.service.ts`** builds `/health` as `${environment.bffApiBaseUrl}/health`. ## What this PR explicitly does NOT do - **No `environment.staging.ts` / `environment.prod.ts`** yet. The ADR says "ship later" for those, and the real prod / staging URLs are unknown until the infrastructure ADR lands. Dropping plausible-but-wrong URLs into the repo would be worse than waiting. - **No `fileReplacements` configuration in `project.json`** — it depends on the per-environment files existing. Wired in the same PR that introduces them. - **No BFF-side audit pool split** (`AUDIT_DATABASE_URL` validator, second Prisma client, boot-time UPDATE-rejection self-test). Also in the ADR's Confirmation list, but it touches `AuditModule` and deserves its own review. Separate PR. - **No `SERVICE_VERSION` wiring** in `tracing.ts`. Still hard-coded to `'dev'`; the build-time version source (same one that will feed the footer's dev-only version badge) is its own small chantier. ## Test plan - [x] `pnpm exec nx run-many -t lint test build --projects=portal-shell` — green (36 / 36 specs unchanged, no new tests needed). - [x] Production build size unchanged (121 kB gzip initial — `environment.ts` is one literal object inlined by the bundler). - [ ] Manual: `pnpm exec nx serve portal-shell` → home page loads, the health widget hits the BFF, Jaeger shows the SPA `document_load` + `fetch` + BFF child span trace. - [ ] Manual: temporarily change `bffApiBaseUrl` to `http://localhost:9999/api` → the fetch fails (expected), and the `traceparent` propagation regex no longer matches `:3000` (verifiable in Network panel — header is absent on cross-origin requests).
julien added 1 commit 2026-05-11 12:48:21 +02:00
feat(portal-shell): wire environment.ts per ADR-0018
CI / scan (pull_request) Successful in 2m21s
CI / commits (pull_request) Successful in 2m21s
CI / check (pull_request) Successful in 2m31s
CI / a11y (pull_request) Successful in 2m38s
CI / perf (pull_request) Successful in 4m51s
03733feeb1
Create `src/environments/environment.ts` holding the two SPA
per-environment values referenced by ADR-0018: `bffApiBaseUrl`
(default `http://localhost:3000/api`) and `otlpEndpoint` (default
`http://localhost:4318/v1/traces`). The dev defaults match the
current local Docker compose stack — `nx serve portal-shell` keeps
working unchanged.

Replace the hard-coded URLs at the two call sites:

- `observability/tracing.ts` reads `environment.otlpEndpoint` for the
  OTLP exporter, and derives the `propagateTraceHeaderCorsUrls`
  regex from `environment.bffApiBaseUrl` — a future deploy-time
  change to the BFF origin propagates `traceparent` to the right
  place automatically.
- `home-status.service.ts` builds the `/health` URL as
  `${environment.bffApiBaseUrl}/health`.

Per-environment siblings (`environment.staging.ts`,
`environment.prod.ts`) and the `fileReplacements` configuration in
`project.json` land later — explicitly out of scope today per the
ADR ("ship later"); their values are not known yet and dropping
plausible-but-wrong production URLs into the repo would be worse
than waiting for the infrastructure ADR.
julien merged commit 8f125d2a90 into main 2026-05-11 12:48:56 +02:00
julien deleted branch feat/portal-shell/environment-ts-wiring 2026-05-11 12:48:59 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: julien/apf_portal#90