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>
Added task recovery system that allows users to recover and save
analysis results even if they accidentally close the page:
1. New pending-task.ts utility:
- Saves task info to localStorage when analysis starts
- Clears after task completes/fails
- 24-hour expiry for old tasks
2. PendingTaskRecovery component:
- Shows on history page if pending task found
- Polls API for task status
- Saves result to IndexedDB + cloud upon completion
3. Updated useAnalysis hook:
- Tracks pending tasks in localStorage
- Clears on completion/failure
Now users visiting /history after closing the page during analysis
will see a prompt to recover and save their completed report.