feat(spa): proxy /api in dev-server, relative bffApiBaseUrl
Make the SPAs reach the BFF same-origin via the Angular dev-server's
proxy, so the dockerised dev mode (ADR-0030) works when the SPA is
accessed from a remote browser (e.g. http://<vm-ip>:4200/) — and CORS
is bypassed in dev altogether.
- New proxy.conf.js per SPA: /api -> ${BFF_TARGET:-http://localhost:3000}
(JS form so the env var can swap the target at startup without a
rebuild).
- project.json serve.options.proxyConfig wired in for both apps.
- environment.ts (shell + admin) bffApiBaseUrl: 'http://localhost:3000/api'
-> '/api'. Production siblings can still set an absolute origin if
the SPA and BFF live on different hosts; tracing.ts resolves either
form against window.location.origin.
- tracing.ts: new URL(env, window.location.origin) — relative bases no
longer throw, absolute bases keep their own origin.
- dev.compose.yml: BFF_TARGET=http://portal-bff:3000 on portal-shell
and portal-admin so the proxy hits the BFF container by Compose DNS.
Native nx serve leaves it unset and falls back to localhost.
OTel exporter URL and cross-SPA links remain absolute — same remote-
browser issue, but not blocking the 'Backend unreachable' path this
PR targets. Out of scope here, follow-up if needed.
Stacked on top of feat/dockerised-dev-mode.
This commit is contained in:
@@ -84,7 +84,8 @@
|
||||
"continuous": true,
|
||||
"executor": "@angular/build:dev-server",
|
||||
"options": {
|
||||
"port": 4300
|
||||
"port": 4300,
|
||||
"proxyConfig": "apps/portal-admin/proxy.conf.js"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Angular dev-server proxy for portal-admin.
|
||||
//
|
||||
// Mirrors apps/portal-shell/proxy.conf.js — same rationale, same
|
||||
// `/api → ${BFF_TARGET:-http://localhost:3000}` rule. The admin app
|
||||
// talks to the same BFF (ADR-0020 §"Where does the admin app live"),
|
||||
// just at admin-specific paths under `/api/admin/...`; the proxy
|
||||
// match on `/api` covers both surfaces.
|
||||
//
|
||||
// JS form deliberate — only this form can read `process.env` so the
|
||||
// Docker / native target swap (BFF_TARGET in dev.compose.yml) works
|
||||
// without a rebuild.
|
||||
|
||||
const target = process.env['BFF_TARGET'] ?? 'http://localhost:3000';
|
||||
|
||||
module.exports = {
|
||||
'/api': {
|
||||
target,
|
||||
secure: false,
|
||||
changeOrigin: true,
|
||||
},
|
||||
};
|
||||
@@ -13,13 +13,17 @@
|
||||
*/
|
||||
export const environment = {
|
||||
/**
|
||||
* Origin + prefix of the BFF HTTP API. Same value as portal-shell
|
||||
* — both SPAs talk to the same BFF (per ADR-0020 §"Where does
|
||||
* the admin app live"). The admin-specific routing happens via
|
||||
* the `AUTH_PATH_PREFIX` token (`/admin/auth`) provided in
|
||||
* Prefix of the BFF HTTP API. Same value as portal-shell — both
|
||||
* SPAs talk to the same BFF (per ADR-0020 §"Where does the admin
|
||||
* app live"). The admin-specific routing happens via the
|
||||
* `AUTH_PATH_PREFIX` token (`/admin/auth`) provided in
|
||||
* `app.config.ts`, not by talking to a different host.
|
||||
*
|
||||
* Relative path: see portal-shell `environment.ts` for the full
|
||||
* rationale. Both SPAs use `proxy.conf.js` to proxy `/api/*` to
|
||||
* the BFF, keeping every call same-origin in the browser.
|
||||
*/
|
||||
bffApiBaseUrl: 'http://localhost:3000/api',
|
||||
bffApiBaseUrl: '/api',
|
||||
|
||||
/**
|
||||
* Name of the BFF's CSRF cookie. v1 reuses `portal_csrf`
|
||||
|
||||
Reference in New Issue
Block a user