Getting on Vercel "Error: Body exceeded 50000kb limit". Not sending files, it's a basic send email.
Unanswered
Bee posted this in #help-forum
BeeOP
I'm creating an API route to send emails with Sendgrid, no files. I get the error on build time. I removed the API route, and the build passes, so I'm 100% sure the error is in there.
Here is the code for the route (I hid the emails, but that is not in the original code):
Here is the code for the route (I hid the emails, but that is not in the original code):
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
export const config = {
maxDuration: 5,
};
function getSupportEmail() {
const locale = process.env.NEXT_PUBLIC_LOCALE;
if (locale === "en-CA" || locale === "fr-CA") {
return "****@***.***";
} else {
return "****@****.***";
}
}
export default async function formHandler(req, res) {
const { email, name, message } = req.body;
const msg = {
to: getSupportEmail(),
from: email || "",
subject: `New Message from ${name || ""}`,
text: message || "",
};
try {
await sgMail.send(msg);
res.json({ message: "Email sent successfully" });
} catch (error) {
console.error(error); // Optional: Log the error for debugging
res.status(500).json({ error: "Failed to send email" });
}
}