From a2611369c3f26624bccb4b5fcd14bb6f35e30448 Mon Sep 17 00:00:00 2001 From: Tudor Date: Mon, 2 Feb 2026 21:23:45 +0000 Subject: [PATCH] Fix API URL for server-side vs client-side requests 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 --- nextjs-app/lib/api.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nextjs-app/lib/api.ts b/nextjs-app/lib/api.ts index 591a1da..3b28132 100644 --- a/nextjs-app/lib/api.ts +++ b/nextjs-app/lib/api.ts @@ -20,7 +20,11 @@ import type { // 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) export const CACHE_DURATION = {