mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 02:31:53 +02:00
✨ Use message queue for emails (#1446)
This commit is contained in:
parent
673fc79801
commit
a452e5b764
12 changed files with 150 additions and 35 deletions
|
@ -42,6 +42,7 @@
|
|||
"@trpc/next": "^10.13.0",
|
||||
"@trpc/react-query": "^10.13.0",
|
||||
"@trpc/server": "^10.13.0",
|
||||
"@upstash/qstash": "^2.7.17",
|
||||
"@upstash/ratelimit": "^1.2.1",
|
||||
"@vercel/functions": "^1.0.2",
|
||||
"@vercel/kv": "^2.0.0",
|
||||
|
|
33
apps/web/src/app/api/send-email/route.ts
Normal file
33
apps/web/src/app/api/send-email/route.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import * as Sentry from "@sentry/nextjs";
|
||||
import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { getEmailClient } from "@/utils/emails";
|
||||
|
||||
const emailClient = getEmailClient();
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
/**
|
||||
* We need to call verifySignatureAppRouter inside the route handler
|
||||
* to avoid the build breaking when env vars are not set.
|
||||
*/
|
||||
return verifySignatureAppRouter(async (req: NextRequest) => {
|
||||
const body = await req.json();
|
||||
|
||||
// TODO: Add validation for templateName and options
|
||||
|
||||
try {
|
||||
await emailClient.sendTemplate(body.templateName, body.options);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
Sentry.captureException(error);
|
||||
|
||||
return NextResponse.json(
|
||||
{ success: false, error: "Failed to send email" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
})(req);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue