Fix API URL for server-side vs client-side requests
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 35s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m15s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s

Use FASTAPI_URL for SSR (internal Docker network: http://backend:80/api)
Use NEXT_PUBLIC_API_URL for browser requests (http://localhost:8000/api)

Fixes ECONNREFUSED error during server-side rendering.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Tudor
2026-02-02 21:23:45 +00:00
parent 28acabd433
commit a2611369c3

View File

@@ -20,7 +20,11 @@ import type {
// Configuration // Configuration
// ============================================================================ // ============================================================================
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || '/api'; // Use FASTAPI_URL for server-side requests (internal Docker network)
// Use NEXT_PUBLIC_API_URL for client-side requests (browser)
const API_BASE_URL = typeof window === 'undefined'
? (process.env.FASTAPI_URL || process.env.NEXT_PUBLIC_API_URL || '/api')
: (process.env.NEXT_PUBLIC_API_URL || '/api');
// Cache configuration for server-side fetching (Next.js revalidate) // Cache configuration for server-side fetching (Next.js revalidate)
export const CACHE_DURATION = { export const CACHE_DURATION = {