From 20d55365431bfea0cf5279670f9ce018071256c4 Mon Sep 17 00:00:00 2001 From: Ankit Dash Date: Tue, 9 Jul 2024 17:50:49 +0530 Subject: [PATCH] fix undefined errors --- apps/studio-next/src/app/api/crawler/route.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/studio-next/src/app/api/crawler/route.tsx b/apps/studio-next/src/app/api/crawler/route.tsx index 227ee9b5c..400bc00a5 100644 --- a/apps/studio-next/src/app/api/crawler/route.tsx +++ b/apps/studio-next/src/app/api/crawler/route.tsx @@ -8,7 +8,21 @@ export async function GET(request: NextRequest) { if (!searchParams) return new NextResponse(null, { status: 200 }); const info: DocumentInfo = await parseURL(searchParams); - const ogImageurl = `https://ogp-studio.netlify.app/api/og?title=${encodeURIComponent(info.title!)}&description=${encodeURIComponent(info.description!)}&numServers=${info.numServers}&numChannels=${info.numChannels}`; + let ogImageParams = new URLSearchParams(); + + if (info.title !== undefined) { + ogImageParams.append('title', encodeURIComponent(info.title)); + } + if (info.description !== undefined) { + ogImageParams.append('description', encodeURIComponent(info.description)); + } + if (info.numServers !== undefined) { + ogImageParams.append('numServers', info.numServers.toString()); + } + if (info.numChannels !== undefined) { + ogImageParams.append('numChannels', info.numChannels.toString()); + } + const ogImageurl = `https://ogp-studio.netlify.app/api/og?${ogImageParams.toString()}`; const crawlerInfo = `