From c8b601f2648f524bafb8e8e45205ba2ee16b90b2 Mon Sep 17 00:00:00 2001 From: valentinarau Date: Thu, 7 Mar 2024 13:03:14 -0300 Subject: [PATCH] fix undefined url --- pages/index.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 0121aa6..bcdf01c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -31,7 +31,7 @@ export const getServerSideProps: GetServerSideProps = async ( try { const googleMapsApiKey = process.env.GOOGLE_MAPS_API_KEY; const webSocketURL = process.env.WEBSOCKET_URL; - const currentBoats = await fetchBoats(); + const currentBoats = await fetchBoats(process.env.BASE_URL); if (!googleMapsApiKey) { throw new Error('Environment variable not set: GOOGLE_MAPS_API_KEY'); @@ -74,8 +74,8 @@ const parseBoat = (deviceSample: any): Boat => { }; }; -const fetchBoats = async () => { - const data = await axios.get(`${process.env.BASE_URL}/api/external-samples?lastHour=true`, {}); +const fetchBoats = async (baseUrl: any) => { + const data = await axios.get(`${baseUrl}/api/external-samples?lastHour=true`, {}); return JSON.parse(JSON.stringify( data.data.samples.map((sample: any) => parseBoat({ ...sample, name: sample.device.name })))); }; @@ -112,8 +112,9 @@ const MapWithVehicles: NextPage = ({ useEffect(() => { const interval = setInterval(async () => { - const newBoats = await fetchBoats() + const newBoats = await fetchBoats("") setBoats(newBoats) + console.log(newBoats) }, 20000); return () => clearInterval(interval); }, []);