fresh-main #1
|
@ -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 }) => {
|
|||
<p><strong>Message:</strong></p>
|
||||
<p>${data.message.replace(/\n/g, '<br>')}</p>
|
||||
`,
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue