From d8e12c48afbfdc6eda6f04e844c0d6eab36ef078 Mon Sep 17 00:00:00 2001 From: Owen Rees Date: Mon, 12 Jun 2023 20:47:58 +0200 Subject: [PATCH] env variables changes --- hooks/useTournamentFilter.tsx | 2 +- utils/getTournamentData.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hooks/useTournamentFilter.tsx b/hooks/useTournamentFilter.tsx index eec3d05..368803c 100644 --- a/hooks/useTournamentFilter.tsx +++ b/hooks/useTournamentFilter.tsx @@ -16,7 +16,7 @@ const useTournamentDataFilter = ( if (filtered.length === 0) { state = ( - + No tournaments found diff --git a/utils/getTournamentData.tsx b/utils/getTournamentData.tsx index 4048d3f..6797259 100644 --- a/utils/getTournamentData.tsx +++ b/utils/getTournamentData.tsx @@ -3,11 +3,16 @@ * @remarks The result is cached for the revalidation period in seconds */ export default async function getTournaments(country: string) { - const baseUrl = process.env.VERCEL_URL - ? `https://${process.env.VERCEL_URL}` - : "http://localhost:3000"; + const baseUrl = + process.env.NODE_ENV === "production" + ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` + : "http://localhost:3000"; const res = await fetch(`${baseUrl}/api/tournaments/${country}`, { next: { revalidate: 300 }, }); - return await res.json(); + + if (res.status !== 200) { + throw new Error("Failed to fetch tournament data"); + } + return res.json(); }