#8402: fix(ui): bypass /api in Control UI handler
app: web-ui
gateway
stale
Cluster:
Device Auth and Security Fixes
**Summary**
- Skip Control UI SPA fallback for `/api` routes to return JSON responses. Fixes #8183.
- Add a focused gateway unit test for `/api` bypass behavior.
**Testing**
- `pnpm vitest run --config vitest.gateway.config.ts src/gateway/control-ui.http.test.ts`
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts the Control UI HTTP handler so that requests targeting `/api` (both at the root and under a configured Control UI `basePath`) bypass the SPA fallback logic and can be handled by downstream JSON/API routing. It also adds a focused gateway unit test to assert that `/api/*` paths are not claimed by the Control UI handler.
The change fits into the gateway request pipeline by making `handleControlUiHttpRequest` return `false` for API routes, allowing the gateway’s API router/middleware to respond instead of serving `index.html`.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and addresses the intended routing bug with low surface area changes.
- The bypass logic is simple and the added test covers both root and nested base paths. Main remaining concern is an observable behavior change for non-GET/HEAD requests to `/api/*` when `basePath` is empty (previously 405, now falls through), which may or may not be desired depending on the gateway chain.
- src/gateway/control-ui.ts (method gating vs /api bypass ordering)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21186: fix(gateway): strict loopback guard for Control UI (v2)
by dinakars777 · 2026-02-19
78.4%
#13960: fix(ui): preserve structured config validation error details
by constansino · 2026-02-11
77.1%
#20089: fix(gateway): preserve control-ui scopes when dangerouslyDisableDev...
by vashkartik · 2026-02-18
76.9%
#17753: fix: Control UI unusable over HTTP - missing scopes
by MisterGuy420 · 2026-02-16
76.2%
#17378: fix(gateway): allow dangerouslyDisableDeviceAuth with trusted-proxy...
by ar-nadeem · 2026-02-15
75.0%
#21326: Security/UI: harden Control UI gatewayUrl URL overrides
by bmendonca3 · 2026-02-19
74.4%
#9218: Fix Control UI chat resync on gaps and terminal events
by figitaki · 2026-02-05
74.0%
#6352: fix(ux): update gateway token error message UI location
by Glucksberg · 2026-02-01
73.4%
#21100: Security/Gateway: require explicit break-glass env for Control UI b...
by bmendonca3 · 2026-02-19
72.8%
#23465: Gateway: strengthen Control UI security headers
by bmendonca3 · 2026-02-22
72.5%