From b565d07d17c2948c586102fe9c76639153ed78f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 11 Jun 2026 08:11:27 +0000 Subject: [PATCH 1/2] Fix syntax error in contact API route breaking Vercel build - Remove stray closing paren on the msg object literal (the build-breaking syntax error) - Destructure recaptchaToken from the request body (was referenced but undefined) - Actually send the composed message via sendEmail(msg) --- app/api/contact/route.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index 4d82a3a..30825bc 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -6,7 +6,7 @@ export const dynamic = 'force-dynamic' export async function POST(request: NextRequest) { try { - const { name, email, message } = await request.json() + const { name, email, message, recaptchaToken } = await request.json() // Verify reCAPTCHA first const recaptchaResponse = await fetch('https://www.google.com/recaptcha/api/siteverify', { @@ -38,7 +38,9 @@ export async function POST(request: NextRequest) {

Message:

${message}

` - }) + } + + await sendEmail(msg) return NextResponse.json({ success: true }) } catch (error) { From 589cb4ebb6d2ddbe2a82a44dac74f3f91a5aaa90 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 11 Jun 2026 08:16:18 +0000 Subject: [PATCH 2/2] Configure SendGrid API key lazily to avoid build-time crash lib/sendgrid threw at module import when SENDGRID_API_KEY was unset, which crashed Next.js build-time page-data collection for /api/contact on Vercel. Defer the key configuration (and the missing-key error) to the first sendEmail call so the build no longer depends on the env var being present. --- lib/sendgrid.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/sendgrid.ts b/lib/sendgrid.ts index 7ec38b5..792a9aa 100644 --- a/lib/sendgrid.ts +++ b/lib/sendgrid.ts @@ -1,13 +1,19 @@ import sgMail from '@sendgrid/mail' -if (!process.env.SENDGRID_API_KEY) { - throw new Error('SENDGRID_API_KEY is not set') -} +let apiKeyConfigured = false -sgMail.setApiKey(process.env.SENDGRID_API_KEY) +const configureApiKey = () => { + if (apiKeyConfigured) return + if (!process.env.SENDGRID_API_KEY) { + throw new Error('SENDGRID_API_KEY is not set') + } + sgMail.setApiKey(process.env.SENDGRID_API_KEY) + apiKeyConfigured = true +} export const sendEmail = async (options: sgMail.MailDataRequired) => { try { + configureApiKey() await sgMail.send(options) return { success: true } } catch (error: any) {