feat(spa): opt-in 'https' nx serve config for dev-server TLS (#263)
## Summary
Add an opt-in `https` configuration to the SPA dev-servers so the ADR-0030 dockerised dev mode can be reached over a hostname registered in Entra. Entra refuses `http:` redirect URIs for anything other than `localhost`, which made the hostname-based access pattern (`apf-portal.dev-jg.local`, `apf-portal.dev.local`, …) — the only stable way to share a VM-based dev stack with another developer — impossible to wire to OIDC. This PR closes that gap without touching the WSL-native + localhost flow.
## What lands
| File | Change |
| --- | --- |
| `apps/portal-shell/project.json`, `apps/portal-admin/project.json` | New `https` Nx serve configuration: inherits the `development` build, sets `ssl: true` + `sslKey: .secrets/dev-tls.key` + `sslCert: .secrets/dev-tls.pem`. `defaultConfiguration` stays `development`; the `https` config is purely opt-in. |
| `infra/local/dev.compose.yml` | The `portal-shell` and `portal-admin` commands now end with `--configuration=${NX_SERVE_CONFIGURATION:-development}`. Compose interpolates the value at YAML parse time from `infra/local/.env`. Default is `development` (no SSL), so behaviour is unchanged for anyone who doesn't opt in. |
| `infra/local/.env.example` | New commented-out `NX_SERVE_CONFIGURATION=https` block with the rationale + pointer to the mkcert setup. |
| `apps/portal-bff/.env.example` | Comment block above the `ENTRA_*_REDIRECT_URI` defaults shows the HTTPS hostname-based override pattern (the four URIs that go with the `apps` profile when accessing via a hostname) and reminds that each override must be registered Entra-side. |
| `infra/README.md` | New "HTTPS dev-server setup — remote-browser access via a hostname" subsection: mkcert install / `mkcert -install`, cert generation, `.secrets/dev-tls.{key,pem}` convention, Entra registration reminder, `NX_SERVE_CONFIGURATION=https` opt-in. Notes that WSL-native is unaffected and that the cert path stays the same when the corp CA eventually replaces mkcert. |
## Design notes
- **Convention `.secrets/dev-tls.{key,pem}` at repo root.** Matches the existing `apps/portal-bff/.secrets/jwks.pem` pattern (gitignored via `*.pem` + `*.key`). Workspace-relative path means project.json can hardcode it and each dev drops their per-host cert there.
- **Hardcoded path, per-dev cert content.** Each developer generates a cert for **their own** hostname; the cert sits at the same fixed path on every machine. Nothing dev-specific in `project.json`.
- **`https` is opt-in, not default.** Native `nx serve` keeps booting on HTTP (`localhost:4200`) without SSL key files, exactly as before. Compose default is also `development` — only setting `NX_SERVE_CONFIGURATION=https` in `infra/local/.env` switches it on, gated by the dev having actually run the mkcert step.
- **BFF stays plain HTTP.** Only the SPA dev-server terminates TLS — the proxy then hits `http://portal-bff:3000` on the internal Compose network. Entra still gets HTTPS at the browser-facing origin, which is what its policy enforces.
## What this PR deliberately does NOT do
- It does **not** force-enable HTTPS. Devs who don't care about hostname access continue working as before.
- It does **not** touch the BFF code, the Entra config helpers, or the auth flow itself. The whole change is config (project.json + compose + env-examples) + docs.
- It does **not** ship the shared VM cert story. That needs a corp-CA-signed cert (or a shared mkcert CA distributed across workstations); flagged in the README section as a follow-up.
## Test plan
- [x] Both `project.json` files parse as JSON; `nx show project` exposes the new `https` configuration with the expected SSL options.
- [x] `docker compose -f dev.compose.yml --profile apps config` validates with `NX_SERVE_CONFIGURATION=https` (resolves to `--configuration=https`) and without it (resolves to `--configuration=development`).
- [ ] **On vm-jg**: `mkcert -install` on the workstation, `mkcert` against `apf-portal.dev-jg.local`, copy `.secrets/dev-tls.{key,pem}` to the VM, set `NX_SERVE_CONFIGURATION=https` in `infra/local/.env`, register the four `https://apf-portal.dev-jg.local:*` URIs in Entra, restart `dev.sh up apps`, then open `https://apf-portal.dev-jg.local:4200/` from the workstation → SPA loads, no cert warning, sign-in completes and returns to the SPA via the OIDC callback.
- [ ] Native WSL flow unchanged: `nx serve portal-shell` still boots on `http://localhost:4200/`, OIDC against the existing `http://localhost:3000/...` Entra URIs still works.
## Related
- [ADR-0030](docs/decisions/0030-dockerised-dev-mode.md) — the dockerised dev mode this completes for the hostname-access case.
- [ADR-0018](docs/decisions/0018-environment-configuration-strategy.md) — per-environment SPA config strategy; `https` is a new Nx serve _configuration_, not a new `environment.ts` sibling, so 0018's build-time replacement story is unchanged.
- [ADR-0009](docs/decisions/0009-auth-flow-oidc-pkce-msal-node.md) — OIDC flow; no behaviour change, only the redirect-URI strings.
---------
Co-authored-by: Julien Gautier <julien.gautier@apf.asso.fr>
Reviewed-on: #263
This commit was merged in pull request #263.
This commit is contained in:
@@ -35,3 +35,20 @@ OTEL_HTTP_PORT=4318
|
||||
PGWEB_PORT=8081
|
||||
JAEGER_UI_PORT=16686
|
||||
SERVE_STATIC_PORT=4200
|
||||
|
||||
# ---------------------------------------------------------------- Apps (`--profile apps`)
|
||||
# Nx serve configuration for the SPA dev-servers. Two values matter:
|
||||
# - `development` (default) — plain HTTP. Use with `localhost`
|
||||
# browser access; Entra accepts
|
||||
# `http://localhost:*` redirect URIs.
|
||||
# - `https` — TLS-terminating dev-server using the
|
||||
# cert at `.secrets/dev-tls.{key,pem}`.
|
||||
# Required when accessing the SPA via a
|
||||
# hostname (e.g. `apf-portal.dev.local`)
|
||||
# since Entra rejects `http:` for any
|
||||
# non-`localhost` redirect URI. See the
|
||||
# "HTTPS dev-server setup" section of
|
||||
# infra/README.md for the mkcert
|
||||
# procedure and how to wire the
|
||||
# matching `ENTRA_REDIRECT_URI` value.
|
||||
# NX_SERVE_CONFIGURATION=https
|
||||
|
||||
@@ -266,7 +266,27 @@ services:
|
||||
# /api proxy at the BFF container by name (Compose DNS). Native
|
||||
# `nx serve` leaves BFF_TARGET unset and falls back to localhost.
|
||||
BFF_TARGET: http://portal-bff:3000
|
||||
command: ['pnpm', 'exec', 'nx', 'serve', 'portal-shell', '--host', '0.0.0.0', '--port', '4200']
|
||||
# `--configuration=${NX_SERVE_CONFIGURATION:-development}` is
|
||||
# interpolated by Compose at YAML parse time from
|
||||
# `infra/local/.env`. Set `NX_SERVE_CONFIGURATION=https` there to
|
||||
# serve over TLS — required when accessing via a hostname (Entra
|
||||
# rejects `http:` for non-`localhost` redirect URIs). See the
|
||||
# `https` configuration in apps/portal-shell/project.json + the
|
||||
# "HTTPS dev-server setup" section in infra/README.md for the
|
||||
# mkcert procedure.
|
||||
command:
|
||||
[
|
||||
'pnpm',
|
||||
'exec',
|
||||
'nx',
|
||||
'serve',
|
||||
'portal-shell',
|
||||
'--host',
|
||||
'0.0.0.0',
|
||||
'--port',
|
||||
'4200',
|
||||
'--configuration=${NX_SERVE_CONFIGURATION:-development}',
|
||||
]
|
||||
ports:
|
||||
- '${SHELL_PORT:-4200}:4200'
|
||||
depends_on:
|
||||
@@ -279,7 +299,20 @@ services:
|
||||
environment:
|
||||
# See portal-shell — same proxy target for the admin SPA.
|
||||
BFF_TARGET: http://portal-bff:3000
|
||||
command: ['pnpm', 'exec', 'nx', 'serve', 'portal-admin', '--host', '0.0.0.0', '--port', '4300']
|
||||
# See portal-shell for the NX_SERVE_CONFIGURATION rationale.
|
||||
command:
|
||||
[
|
||||
'pnpm',
|
||||
'exec',
|
||||
'nx',
|
||||
'serve',
|
||||
'portal-admin',
|
||||
'--host',
|
||||
'0.0.0.0',
|
||||
'--port',
|
||||
'4300',
|
||||
'--configuration=${NX_SERVE_CONFIGURATION:-development}',
|
||||
]
|
||||
ports:
|
||||
- '${ADMIN_PORT:-4300}:4300'
|
||||
depends_on:
|
||||
|
||||
Reference in New Issue
Block a user