Update BFF routes after backend or path restructure
Goal: fix broken SPA calls after service renames, path changes, or config moves.
Prereqs
- BFF running with
ServiceConfigs/BFF/configmounted to/app/config - Access to edit
routes.yaml,settings.yaml, andpdp.yaml
Where to change things
ServiceConfigs/BFF/config/services(insideroutes.yaml): base URLs/timeouts per upstreamServiceConfigs/BFF/config/routes.yaml: clientpath,target_service,upstream_path,methods,auth,authzServiceConfigs/BFF/config/pdp.yaml:endpoint_mapfor resource/action/id mappingServiceConfigs/BFF/config/settings.yaml: CORS allowlist and redirect origins (dev vs prod)
Common symptoms → likely causes
- 404 at
/api/...: missing or mismatchedpathinroutes.yaml; Traefik not routing/api/**to BFF - 401: missing session/cookies or wrong CORS/base URL in dev
- 403 with
NoMapping: missing or outdatedendpoint_mapentry inpdp.yaml - 403 with
Deny: PDP policy denies; mapping exists but subject lacks permission - 502/timeout: wrong
services.*.base_urlor upstream down
Step-by-step
- Verify Traefik forwards
/api/**to BFF on your host- Check Traefik config/labels for your host:
PathPrefix(/api/)→ BFF service
- Check Traefik config/labels for your host:
- Update services and upstreams
- In
routes.yaml:services, ensure the renamed service andbase_urlare correct (port/path)
- In
- Update route entries
- Ensure
pathreflects the new client shape (canonical/api/<app>/*) - Point
target_serviceat the correct service key - Update
upstream_pathto match backend path; use{path}when forwarding a suffix - Set
auth: session(orbearerfor M2M) andauthz: pdpif PDP applies
- Ensure
- Update PDP endpoint mapping
- In
pdp.yaml:endpoint_map, add/update exact or templated keys for the new client path(s) - Ensure methods map to
resource,action, and optionallyid_fromandprops(JSONPath)
- In
- Align per-service token audiences (if
target_servicechanged)- See How‑to → Session-to-service token bridging; ensure the service name is recognized for token minting
- Dev vs prod base URL and CORS
- Dev: set
VITE_BFF_BASE_URLto the BFF origin (e.g.,http://localhost:8000/api) and include your UI origin in CORS insettings.yaml - Prod: same-origin; set
VITE_BFF_BASE_URLto/api
- Dev: set
Quick validation
# Health
curl -v http://<bff-host>/health
# Expect 401 when unauthenticated
curl -v http://<bff-host>/api/<app>/items
# After login (browser), expect 200 or 403 depending on PDP
# Check BFF logs for mapping lines and PDP decision
Minimal examples
ServiceConfigs/BFF/config/routes.yaml (excerpt)
services:
my_service:
base_url: "http://my-service:8080"
routes:
- id: "my-items"
path: "/api/myapp/items/*"
target_service: "my_service"
upstream_path: "/items/{path}"
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
auth: "session"
authz: "pdp"
ServiceConfigs/BFF/config/pdp.yaml (excerpt)
endpoint_map:
/api/myapp/items:
GET:
resource: "my:item"
action: "list"
/api/myapp/items/{id}:
GET:
resource: "my:item"
action: "read"
id_from: "{id}"
Triage checklist
- VITE base URL correct; avoid double
/api - Traefik forwards
/api/**to BFF - Route
pathandupstream_pathmatch new shapes - Service
base_urlpoints to correct host/port endpoint_mapcovers new paths/methods- Token audience mapping matches
target_service - CORS allowlist covers dev origin
See also
- Reference → YAML proxy (routes.yaml)
- Reference → routes.yaml Reference
- How‑to → Session-to-service token bridging
- How‑to → Validate endpoint_map entries
- Tutorials → React SPA + BFF — Golden Path