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 support for mailto: links

Steven Teya015d62ead8e
diff --git a/.gitignore b/.gitignore
index 28cd23698e..ecd4e2d4e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,7 @@ next-env.d.ts
# miscellaneous
/pages/api/scripts*
apps/docs/openapi.json
+packages/stripe-app/.build/*
.react-email
.contentlayer
.vscode
diff --git a/apps/web/app/mailto/[url]/page.tsx b/apps/web/app/mailto/[url]/page.tsx
new file mode 100644
index 0000000000..6f6291f2e9
--- /dev/null
+++ b/apps/web/app/mailto/[url]/page.tsx
@@ -0,0 +1,15 @@
+import { ClientOnly } from "@dub/ui";
+
+export const runtime = "edge";
+
+export default function MailtoPage({ params }: { params: { url: string } }) {
+ const url = decodeURIComponent(params.url);
+
+ return (
+ <ClientOnly>
+ <head>
+ <meta httpEquiv="refresh" content={`0; url=${url}`} />
+ </head>
+ </ClientOnly>
+ );
+}
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 11e0adc669..45a16e67d0 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -156,6 +156,13 @@ export default async function LinkMiddleware(
DUB_HEADERS,
);
+ // rewrite to mailto page if the link is a mailto link
+ } else if (url.startsWith("mailto:")) {
+ return NextResponse.rewrite(
+ new URL(`/mailto/${encodeURIComponent(url)}`, req.url),
+ DUB_HEADERS,
+ );
+
// rewrite to target URL if link cloaking is enabled
} else if (rewrite) {
if (iframeable) {