From bc132aca10f41b44045121e0b19f2e54292f6048 Mon Sep 17 00:00:00 2001 From: g4ze Date: Sun, 20 Oct 2024 11:52:47 +0530 Subject: [PATCH] env variablkes and public paths --- .env.development | 3 +++ .env.production | 2 ++ src/app/page.jsx | 8 ++++---- src/components/Navbar.jsx | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..a5175b0 --- /dev/null +++ b/.env.development @@ -0,0 +1,3 @@ +# for development only +NEXT_PUBLIC_PUBLIC_PATH="" +# for example public_path/assets/image.jpg diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..21728c9 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# for production only +NEXT_PUBLIC_PUBLIC_PATH=https://gdg-oncampus-bu.github.io/landing-page-WIP/ diff --git a/src/app/page.jsx b/src/app/page.jsx index f0d8e70..e4430c2 100644 --- a/src/app/page.jsx +++ b/src/app/page.jsx @@ -6,11 +6,11 @@ import EventsSection from "@/components/EventsSection"; import Links from "@/components/Links"; export default function Home() { + const publicPath = process.env.NEXT_PUBLIC_PUBLIC_PATH ; const [eventsData, setEventsData] = useState([]); - useEffect(() => { const fetchEventsData = async () => { - const response = await fetch("/data/events.json"); + const response = await fetch(publicPath+"/data/events.json"); const data = await response.json(); setEventsData(data); }; @@ -30,7 +30,6 @@ export default function Home() { }, 600); } }; - return ( <> @@ -38,7 +37,8 @@ export default function Home() {