Commit Graph

11 Commits

Author SHA1 Message Date
MarkLo127 b8454fefc7 Replace next.config.ts rewrites with catch-all API proxy route
The rewrites() approach resolves the backend URL once at server startup,
which always falls back to http://backend:8000 on Railway (where that
Docker Compose hostname doesn't exist). This caused ECONNREFUSED for
/api/analyze and all other proxied routes.

Fix: Add app/api/[...path]/route.ts that resolves the backend URL
per-request via getBackendUrl(), matching the pattern already used by
/api/chat and /api/auth/google/token routes.

Changes:
- New: frontend/app/api/[...path]/route.ts — catch-all proxy (GET/POST/PUT/PATCH/DELETE)
- Removed: frontend/app/api/chat/route.ts — now handled by catch-all
- Updated: frontend/next.config.ts — removed rewrites() block
- Updated: frontend/Dockerfile — cleared NEXT_PUBLIC_API_URL build default

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 11:37:12 +08:00
MarkLo127 ffc36edb97 Fix Railway ECONNREFUSED error by unifying backend URL resolution
Problem: Next.js frontend in production mode falls back to http://backend:8000
(Docker Compose internal hostname) when BACKEND_URL env var is not set.
In Railway's distributed environment, this hostname doesn't exist, causing
ECONNREFUSED errors.

Solution: Create unified getBackendUrl() function with consistent fallback
priority across all server-side proxying files:
1. Explicit BACKEND_URL (for Railway / custom deployment)
2. Development mode -> http://localhost:8000
3. NEXT_PUBLIC_API_URL (may be set in Railway)
4. Docker Compose default -> http://backend:8000

Changes:
- New: frontend/lib/backend-url.ts - centralized URL resolution
- Updated: frontend/next.config.ts - use getBackendUrl()
- Updated: frontend/app/api/chat/route.ts - use getBackendUrl()
- Updated: frontend/app/api/auth/google/token/route.ts - use getBackendUrl()

Railway users must set BACKEND_URL=https://<backend-service>.up.railway.app

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-12 11:03:05 +08:00
MarkLo 8204aff28b 2025-12-13 01:54:47 +08:00
MarkLo 29e53034bb 2025-11-21 23:19:42 +08:00
MarkLo 987e757d8c 2025-11-21 23:12:41 +08:00
MarkLo 15e374d7d0 2025-11-21 21:53:16 +08:00
MarkLo b554ae71d5 2025-11-21 21:28:58 +08:00
MarkLo db3d5754de 2025-11-21 21:14:21 +08:00
MarkLo f3ec43bb2b 2025-11-21 10:23:21 +08:00
MarkLo 710ff8c855 2025-11-21 10:17:55 +08:00
MarkLo 2872f18b47 2025-11-20 21:56:47 +08:00