add a constant file to read the env variables

This commit is contained in:
Yifei Hu 2024-07-12 14:14:59 +08:00
parent 7c5ab7c65f
commit 4007efcc57
4 changed files with 37 additions and 17 deletions

View file

@ -1,7 +1,8 @@
import NewsDetail from "../../../components/NewsDetail";
import { VALIDATED_ENV } from "../../../lib/constants";
async function getNewsData(id: string) {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/news/${id}`, { next: { revalidate: 60 } });
const res = await fetch(`${VALIDATED_ENV.API_URL}/news/${id}`, { next: { revalidate: 60 } });
if (!res.ok) {
throw new Error("Failed to fetch news");
}