Skip to content

Commit

Permalink
fix undefined url
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinarau committed Mar 7, 2024
1 parent 109f64d commit c8b601f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getServerSideProps: GetServerSideProps<ServerSideProps> = 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');
Expand Down Expand Up @@ -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 }))));
};
Expand Down Expand Up @@ -112,8 +112,9 @@ const MapWithVehicles: NextPage<ServerSideProps> = ({

useEffect(() => {
const interval = setInterval(async () => {
const newBoats = await fetchBoats()
const newBoats = await fetchBoats("")
setBoats(newBoats)
console.log(newBoats)
}, 20000);
return () => clearInterval(interval);
}, []);
Expand Down

0 comments on commit c8b601f

Please sign in to comment.