TradingAgents/frontend/lib
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
..
i18n 2026-03-11 18:38:42 +08:00
api-helpers.ts 2025-12-11 00:06:09 +08:00
api.ts 2026-03-10 17:00:32 +08:00
backend-url.ts Fix Railway ECONNREFUSED error by unifying backend URL resolution 2026-03-12 11:03:05 +08:00
crypto.ts 2025-12-13 01:54:47 +08:00
pending-task.ts feat: recover pending analysis tasks after page close 2025-12-14 03:55:12 +08:00
report-utils.ts 2026-03-12 09:30:42 +08:00
reports-db.ts 2026-03-12 09:30:42 +08:00
storage.ts 2026-01-16 00:56:14 +08:00
types.ts 2026-03-10 17:00:32 +08:00
user-api.ts 2026-03-11 20:26:37 +08:00
utils.ts 2025-11-20 21:56:47 +08:00