Skip to content

fix (web): proxy /api requests to backend in production hooks#51

Merged
aybruhm merged 1 commit into
mainfrom
fix/api-proxy-in-production-hooks
Jun 26, 2026
Merged

fix (web): proxy /api requests to backend in production hooks#51
aybruhm merged 1 commit into
mainfrom
fix/api-proxy-in-production-hooks

Conversation

@aybruhm

@aybruhm aybruhm commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

Signing in from the production deployment returned [404] POST /api/v1/auth/login. The login form sends POST /api/v1/auth/login to the web container (SvelteKit Node server on port 3000), but the server hook called resolve(event) — which has SvelteKit search for a route under src/routes/api/. No such route exists, so every API call got a 404.

In dev mode, Vite's proxy config (vite.config.js) handles this transparently. That proxy does not run in production (node build/index.js).

Fix

web/src/hooks.server.ts — the /api/* branch now fetches from the FastAPI backend (PRIVATE_API_URL, default http://api:8000) instead of calling resolve(event). Set-Cookie headers from the API are forwarded so auth tokens
(access_token, refresh_token) reach the browser.

Request flow

Before: browser → web:3000 → SvelteKit route lookup → 404
After: browser → web:3000 → fetch(api:8000) → API response → browser

The SvelteKit server hook was calling resolve(event) for /api/* paths,
which caused SvelteKit to look for a matching route under src/routes/api/.
No such route exists, so every API call returned 404 in production.

In dev mode the Vite proxy handles this, but in production the Node adapter
(node build/index.js) must forward /api requests to the FastAPI backend itself.
The hook now fetches from PRIVATE_API_URL and relays Set-Cookie headers so auth
tokens reach the browser.

Closes login returning [404] POST /api/v1/auth/login.
@aybruhm
aybruhm merged commit e1cf1da into main Jun 26, 2026
4 checks passed
@aybruhm
aybruhm deleted the fix/api-proxy-in-production-hooks branch June 26, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant