Skip to content

Commit cee7eea

Browse files
fix: resolve remaining Copilot review comments
- Return browser-facing origin URL in /config API_URL instead of empty string, so health checks and other API calls route correctly through the frontend reverse proxy - Use error-specific WebSocket close codes (1011 for backend errors, 1000 for normal closure) instead of a blanket close - Remove /config proxy from vite dev server to avoid failures when frontend_server is not running (frontend falls back to defaults) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0c71975 commit cee7eea

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/frontend/frontend_server.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ async def serve_index():
5858

5959

6060
@app.get("/config")
61-
async def get_config():
61+
async def get_config(request: Request):
62+
# The browser receives the frontend's own origin as the API base so that
63+
# all /api/* requests (including /api/health) route through the frontend
64+
# reverse proxy rather than hitting the internal backend directly.
65+
browser_api_url = str(request.base_url).rstrip("/")
6266
config = {
63-
# Return empty string so the browser uses relative /api/* paths
64-
# which are proxied server-side to BACKEND_API_URL. This ensures
65-
# backend Container Apps with internal-only ingress are never
66-
# contacted directly from the browser.
67-
"API_URL": "",
67+
"API_URL": browser_api_url,
6868
"REACT_APP_MSAL_AUTH_CLIENTID": os.getenv(
6969
"REACT_APP_MSAL_AUTH_CLIENTID", "Client ID not set"
7070
),
@@ -133,7 +133,11 @@ async def forward_to_client():
133133
await asyncio.gather(*pending, return_exceptions=True)
134134
except Exception as exc:
135135
logger.error("WebSocket proxy error for batch %s: %s", batch_id, exc)
136-
finally:
136+
try:
137+
await websocket.close(code=1011, reason="backend connection error")
138+
except Exception:
139+
pass
140+
else:
137141
try:
138142
await websocket.close(code=1000, reason="proxy closed")
139143
except Exception:

src/frontend/vite.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ export default defineConfig({
1010
'/api': {
1111
target: 'http://localhost:8000',
1212
changeOrigin: true,
13-
},
14-
'/config': {
15-
target: 'http://localhost:3000',
16-
changeOrigin: true,
17-
// Only proxied when the Python frontend_server is running locally
18-
configure: (proxy) => {
19-
proxy.on('error', () => {});
20-
}
2113
}
2214
}
2315
}

0 commit comments

Comments
 (0)