48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import { EmailTemplate } from "@/components/custom/ContactSender";
|
|
import { Resend } from "resend";
|
|
|
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
|
|
export async function POST(request) {
|
|
try {
|
|
const formData = await request.json();
|
|
|
|
// Send email using Resend
|
|
const { data: resendData, error: resendError } = await resend.emails.send({
|
|
from: "support@rankrunners.net",
|
|
to: ["sales@rankrunners.net"],
|
|
subject: "New Quotes From /contact",
|
|
react: EmailTemplate({
|
|
name: formData.name,
|
|
emailAddress: formData.emailAddress,
|
|
phoneNumber: formData.phoneNumber,
|
|
subject: formData.subject,
|
|
message: formData.message,
|
|
}),
|
|
});
|
|
|
|
if (resendError) {
|
|
return Response.json({ error: resendError }, { status: 500 });
|
|
}
|
|
|
|
const response = await fetch("https://cryagent.pythonanywhere.com/submitrankrunnerscontact", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ email: formData.emailAddress }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Failed to submit to cryagent.pythonanywhere.com");
|
|
}
|
|
|
|
const pythonAnywhereData = await response.json();
|
|
|
|
return Response.json({ resendData, pythonAnywhereData });
|
|
} catch (error) {
|
|
console.error("Error:", error);
|
|
return Response.json({ error: error.message }, { status: 500 });
|
|
}
|
|
}
|