From f04e383ea353024725616c2c03e533f05c73aabd Mon Sep 17 00:00:00 2001 From: Tudor Date: Mon, 2 Feb 2026 22:42:21 +0000 Subject: [PATCH] Fix: Use correct API base URL for client-side fetches The compare screen and school search modal were not working because they were fetching from '/api' directly instead of using the NEXT_PUBLIC_API_URL environment variable that points to the backend. Fixed client-side fetch calls in: - ComparisonView: Fetch comparison data with correct API URL - SchoolSearchModal: Search schools with correct API URL This ensures client-side requests go to the FastAPI backend at the configured URL (e.g., http://localhost:8000/api) rather than trying to hit non-existent Next.js API routes. Fixes comparison screen showing no data when schools are selected. Co-Authored-By: Claude Sonnet 4.5 --- nextjs-app/components/ComparisonView.tsx | 3 ++- nextjs-app/components/SchoolSearchModal.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nextjs-app/components/ComparisonView.tsx b/nextjs-app/components/ComparisonView.tsx index b3bbb1f..c4a4cb4 100644 --- a/nextjs-app/components/ComparisonView.tsx +++ b/nextjs-app/components/ComparisonView.tsx @@ -55,7 +55,8 @@ export function ComparisonView({ // Fetch comparison data if (selectedSchools.length > 0) { - fetch(`/api/compare?urns=${urns}`) + const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL || '/api'; + fetch(`${apiBaseUrl}/compare?urns=${urns}`) .then((res) => res.json()) .then((data) => setComparisonData(data.comparison)) .catch((err) => console.error('Failed to fetch comparison:', err)); diff --git a/nextjs-app/components/SchoolSearchModal.tsx b/nextjs-app/components/SchoolSearchModal.tsx index a100c43..f7734e0 100644 --- a/nextjs-app/components/SchoolSearchModal.tsx +++ b/nextjs-app/components/SchoolSearchModal.tsx @@ -36,7 +36,8 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) { setIsSearching(true); try { - const response = await fetch(`/api/schools?search=${encodeURIComponent(term)}&page_size=10`); + const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL || '/api'; + const response = await fetch(`${apiBaseUrl}/schools?search=${encodeURIComponent(term)}&page_size=10`); const data = await response.json(); setResults(data.schools || []); setHasSearched(true);