diff --git a/src/pages/api/contact.ts b/src/pages/api/contact.ts index f0c8ce7..bcc3c40 100644 --- a/src/pages/api/contact.ts +++ b/src/pages/api/contact.ts @@ -1,10 +1,6 @@ import type { APIRoute } from 'astro'; import { Resend } from 'resend'; -// Initialize Resend with API key from environment variables -// IMPORTANT: Set RESEND_API_KEY in your deployment environment (e.g., Cloudflare Pages) -const resend = new Resend(import.meta.env.RESEND_API_KEY); - // Define the expected structure of the form data interface FormData { name: string; @@ -14,6 +10,10 @@ interface FormData { } export const POST: APIRoute = async ({ request }) => { + // Initialize Resend inside the handler to access runtime env vars/secrets + // IMPORTANT: Set RESEND_API_KEY in your deployment environment (e.g., Cloudflare Pages) + const resend = new Resend(import.meta.env.RESEND_API_KEY); + // Check if API key is configured if (!import.meta.env.RESEND_API_KEY) { console.error("Resend API key is not configured."); @@ -56,7 +56,7 @@ export const POST: APIRoute = async ({ request }) => {

Message:

${data.message.replace(/\n/g, '
')}

`, - reply_to: data.email, // Set the reply-to header to the sender's email + replyTo: data.email, // Set the reply-to header to the sender's email }); if (emailError) {