From 36da0ec4cb35442bec2d8b82f0482beac7016b2a Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Sun, 25 Aug 2024 19:49:48 +0200 Subject: [PATCH] refactor: Update API endpoints to use baseUrl in page.tsx --- src/app/scripts/[id]/page.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/scripts/[id]/page.tsx b/src/app/scripts/[id]/page.tsx index d96189c..6493174 100644 --- a/src/app/scripts/[id]/page.tsx +++ b/src/app/scripts/[id]/page.tsx @@ -17,13 +17,15 @@ type Props = { searchParams: { [key: string]: string | string[] | undefined }; }; +const baseUrl = process.env.NODE_ENV === "production" ? "https://proxmox-helper-scripts.vercel.app" : "http://localhost:3000"; + export async function generateMetadata({ params, searchParams }: Props, parent: ResolvingMetadata ): Promise { const id = params.id; - const data = await fetch(`http://localhost:3000/api/scripts/script?title=${id}`).then((res) => res.json()); - const imgURL = `http://localhost:3000/api/og?title=${data.title}?logo=${data.logo}`; + const data = await fetch(`${baseUrl}/api/scripts/script?title=${id}`).then((res) => res.json()); + const imgURL = `${baseUrl}/api/og?title=${data.title}?logo=${data.logo}`; return { title: `${data.title} | Proxmox VE Helper-Scripts`, @@ -45,7 +47,7 @@ export async function generateMetadata({ params, searchParams }: Props, export default async function Page({ params }: { params: { id: string } }) { const data = await fetch( - `http://localhost:3000/api/scripts/script?title=${params.id}`, + `${baseUrl}/api/scripts/script?title=${params.id}`, ).then((res) => res.json()); return (