-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
Describe the bug
Something really weird is happening in my next api route.
If I use the following code I get a 404
like the route doesn't even exist, no console log is printed, no error is thrown, it's like if I was not calling the correct endpoint.
import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
import AccountCreated from "@/emails/AccountCreated";
import React from "react";
export async function POST(req: Request) {
try {
const transport = nodemailer.createTransport({
host: 'smtp.sendgrid.net',
port: 587,
auth: {
user: 'apikey',
pass: process.env.SENDGRID_API_KEY,
},
});
const sendMail = buildSendMail({
transport,
defaultFrom: "noreply@mysender.com",
configPath: "./mailing.config.json",
});
sendMail({
to: "iam@andireceive.com",
subject: "hello",
component: React.createElement(AccountCreated, { name: "Hello" }),
});
return Response.json({ success: true }, { status: 200 });
}
catch (error) {
return Response.json({ success: false, error: error }, { status: 500 });
}
}
BUT if I put comment the sendMail
part like the following I get a perfect 200 and so console logs are printed, if I put error voluntary it's thrown and printed.
import nodemailer from "nodemailer";
import { buildSendMail } from "mailing-core";
import AccountCreated from "@/emails/AccountCreated";
import React from "react";
export async function POST(req: Request) {
try {
const transport = nodemailer.createTransport({
host: 'smtp.sendgrid.net',
port: 587,
auth: {
user: 'apikey',
pass: process.env.SENDGRID_API_KEY,
},
});
const sendMail = buildSendMail({
transport,
defaultFrom: "noreply@mysender.com",
configPath: "./mailing.config.json",
});
// sendMail({
// to: "iam@andireceive.com",
// subject: "hello",
// component: React.createElement(AccountCreated, { name: "Hello" }),
// });
return Response.json({ success: true }, { status: 200 });
}
catch (error) {
return Response.json({ success: false, error: error }, { status: 500 });
}
}
What in the hell, in the buildSendMail
function cause my next api route to 404? Is that a NextJS thing?
Feel free to ask any additional information if needed.
Versions
nextjs 14.2.4
mailing-core 1.1.0
nodemailer 6.9.14
react 18.3.1
Metadata
Metadata
Assignees
Labels
No labels