From d51e0d650718111c0a07ec34e2cc83ca9004b452 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Mon, 4 May 2026 01:10:18 -0400 Subject: [PATCH] Refactor host URL retrieval in Open Graph API routes for improved error handling Co-authored-by: Copilot --- src/app/api/og/fund/[slug]/route.tsx | 3 ++- src/app/api/og/hashtag/[tag]/route.tsx | 3 ++- src/app/api/og/leaderboard/route.tsx | 3 ++- src/app/api/og/profile/[username]/route.tsx | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/api/og/fund/[slug]/route.tsx b/src/app/api/og/fund/[slug]/route.tsx index e6523a4..b8be26e 100644 --- a/src/app/api/og/fund/[slug]/route.tsx +++ b/src/app/api/og/fund/[slug]/route.tsx @@ -55,7 +55,8 @@ export async function GET( style: 'currency', currency: 'USD', notation: Math.abs(n) >= 10000 ? 'compact' : 'standard', maximumFractionDigits: 2, }).format(n) - const host = new URL(process.env.NEXTAUTH_URL ?? 'http://localhost:3000').host + const rawUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000' + const host = (() => { try { return new URL(rawUrl).host } catch { return rawUrl } })() return new ImageResponse( ( diff --git a/src/app/api/og/hashtag/[tag]/route.tsx b/src/app/api/og/hashtag/[tag]/route.tsx index 251e505..09c7a7e 100644 --- a/src/app/api/og/hashtag/[tag]/route.tsx +++ b/src/app/api/og/hashtag/[tag]/route.tsx @@ -65,7 +65,8 @@ export async function GET( }).format(price) const polyline = buildPolyline(prices) - const host = new URL(process.env.NEXTAUTH_URL ?? 'http://localhost:3000').host + const rawUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000' + const host = (() => { try { return new URL(rawUrl).host } catch { return rawUrl } })() return new ImageResponse( ( diff --git a/src/app/api/og/leaderboard/route.tsx b/src/app/api/og/leaderboard/route.tsx index fdda123..b564b18 100644 --- a/src/app/api/og/leaderboard/route.tsx +++ b/src/app/api/og/leaderboard/route.tsx @@ -33,7 +33,8 @@ export async function GET() { }).format(n) const medals = ['🥇', '🥈', '🥉', '4.', '5.'] - const host = new URL(process.env.NEXTAUTH_URL ?? 'http://localhost:3000').host + const rawUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000' + const host = (() => { try { return new URL(rawUrl).host } catch { return rawUrl } })() return new ImageResponse( ( diff --git a/src/app/api/og/profile/[username]/route.tsx b/src/app/api/og/profile/[username]/route.tsx index 7271759..ec98203 100644 --- a/src/app/api/og/profile/[username]/route.tsx +++ b/src/app/api/og/profile/[username]/route.tsx @@ -46,7 +46,8 @@ export async function GET( }).format(n) const pnlColor = unrealizedPnl >= 0 ? '#34d399' : '#f87171' - const host = new URL(process.env.NEXTAUTH_URL ?? 'http://localhost:3000').host + const rawUrl = process.env.NEXTAUTH_URL || 'http://localhost:3000' + const host = (() => { try { return new URL(rawUrl).host } catch { return rawUrl } })() return new ImageResponse( (