TradingAgents/frontend
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
..
app Fix Railway ECONNREFUSED error by unifying backend URL resolution 2026-03-12 11:03:05 +08:00
components 2026-03-11 15:32:10 +08:00
context 2025-12-12 19:01:49 +08:00
contexts 2026-01-27 13:22:52 +08:00
hooks 2025-12-17 05:41:30 +08:00
lib Fix Railway ECONNREFUSED error by unifying backend URL resolution 2026-03-12 11:03:05 +08:00
public 2025-12-21 02:00:38 +08:00
.dockerignore 2025-12-12 05:43:08 +08:00
.gitignore 2025-11-20 21:56:47 +08:00
Dockerfile 2025-12-23 10:32:58 +08:00
Dockerfile.railway 2026-03-11 16:56:32 +08:00
bun.lock 2026-03-10 19:07:11 +08:00
components.json 2025-11-20 21:56:47 +08:00
eslint.config.mjs 2025-12-12 05:57:55 +08:00
next.config.ts Fix Railway ECONNREFUSED error by unifying backend URL resolution 2026-03-12 11:03:05 +08:00
package.json 2026-03-10 18:58:03 +08:00
postcss.config.mjs 2025-11-20 21:56:47 +08:00
tsconfig.json 2025-11-20 21:56:47 +08:00