I have an API route, with a GET handler. When I deploy the app to Vercel, I can't trigger subsequent emails because the response appears to be cached. What am I doing wrong in the route.ts
export const runtime = "edge";
export const dynamic = "force-dynamic";
const noCacheHeaders = {
"Cache-Control": "no-store, max-age=0",
"Surrogate-Control": "no-store",
"Vercel-CDN-Cache-Control": "no-store",
};
export async function GET() {
const apiKey = process.env.RESEND_API_KEY as string;
const resend = new Resend(apiKey);
const currentDate = new Date().toISOString().split("T")[0];
const defaultSubject = `Daily Email ${currentDate}`;
if (!resend) {
// handle error
}
const to = "[email protected]";
const subject = defaultSubject;
const message = "Here are your links for today";
try {
const data = await resend.emails.send({
from: "[email protected]",
to,
subject,
html: `
<p>Here are your links for ${currentDate}:</p>
<ul>
<li><a href="https://insite.wiki">Insite Wiki</a></li>
<li><a href="https://mattwood.co">Matt Wood</a></li>
</ul>
<p>${message}</p>
`,
});
if (data.error) {
// handler error
}
return new Response(
JSON.stringify({
message: "Email sent",
date_sent: currentDate,
...data.data,
}),
{
status: 201,
headers: {
"Content-Type": "application/json",
...noCacheHeaders,
},
}
);
} catch (error) {
// handler error
}
}