diff --git a/.env.example b/.env.example index 740bd4f8e8..cebcff5008 100644 --- a/.env.example +++ b/.env.example @@ -10,5 +10,5 @@ FLASK_DEBUG=1 DEBUG=TRUE # Front-End Variables -BASENAME=/ -#BACKEND_URL= +VITE_BASENAME=/ +#VITE_BACKEND_URL= diff --git a/src/front/pages/Home.jsx b/src/front/pages/Home.jsx index 3e9f1aefac..8975f680c1 100644 --- a/src/front/pages/Home.jsx +++ b/src/front/pages/Home.jsx @@ -1,16 +1,43 @@ +import React, { useEffect } from "react" import rigoImageUrl from "../assets/img/rigo-baby.jpg"; import useGlobalReducer from "../hooks/useGlobalReducer.jsx"; export const Home = () => { - const {store, dispatch} =useGlobalReducer() + const {store, dispatch} =useGlobalReducer() + + const loadMessage = async () => { + const backendUrl = import.meta.env.VITE_BACKEND_URL + if (!backendUrl) throw new Error("VITE_BACKEND_URL is not defined in .env file") + const response = await fetch( backendUrl + "/api/hello") + const data = await response.json() + if (!response.ok) throw new Error( + `Could not fetch the message from the backend. + Please check if the backend is running and the backend port is public.` + ); + dispatch({type: "set_hello", payload: data}) + return data + } + + useEffect(()=>{ + loadMessage() + },[]) return (
-
+
+