Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add disposable email domains update cron

Tim Wilson93756e1c4b33
diff --git a/apps/web/app/api/cron/disposable-emails/route.ts b/apps/web/app/api/cron/disposable-emails/route.ts
new file mode 100644
index 0000000000..f90d56fcc5
--- /dev/null
+++ b/apps/web/app/api/cron/disposable-emails/route.ts
@@ -0,0 +1,47 @@
+import { handleAndReturnErrorResponse } from "@/lib/api/errors";
+import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
+import { verifyVercelSignature } from "@/lib/cron/verify-vercel";
+import { redis } from "@/lib/upstash";
+import { log } from "@dub/utils";
+import { NextResponse } from "next/server";
+
+// Cron to update the disposable email domains list in Redis
+// Runs every Monday at noon UTC (0 12 * * 1)
+
+export const dynamic = "force-dynamic";
+
+async function handler(req: Request) {
+ try {
+ if (req.method === "GET") await verifyVercelSignature(req);
+ else if (req.method === "POST") await verifyQstashSignature(req);
+
+ // do it
+ const disposableEmails = await fetch(
+ "https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf",
+ );
+
+ const domains = (await disposableEmails.text()).split("\n").filter(Boolean);
+ if (domains.length < 100) {
+ // There should definitely be at least 100 domains - something is wrong
+ throw new Error("Disposable email domains list is too short");
+ }
+
+ // Use a temporary set to avoid emptying the old set
+ await redis.del("disposableEmailDomainsTmp");
+ await redis.sadd("disposableEmailDomainsTmp", ...domains);
+ await redis.rename("disposableEmailDomainsTmp", "disposableEmailDomains");
+
+ return NextResponse.json({
+ response: "success",
+ });
+ } catch (error) {
+ await log({
+ message: `Error updating disposable email domains list: ${error.message}`,
+ type: "cron",
+ });
+
+ return handleAndReturnErrorResponse(error);
+ }
+}
+
+export { handler as GET, handler as POST };
diff --git a/apps/web/vercel.json b/apps/web/vercel.json
index 88b6ad0f8c..67205920c2 100644
--- a/apps/web/vercel.json
+++ b/apps/web/vercel.json
@@ -7,6 +7,10 @@
{
"path": "/api/cron/usage",
"schedule": "0 12 * * *"
+ },
+ {
+ "path": "/api/cron/disposable-emails",
+ "schedule": "0 12 * * 1"
}
],
"functions": {