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 deeplink preview page (DeepLinkPage)

Steven Teyc1311747fb08
diff --git a/apps/web/app/deeplink/[domain]/[key]/action-buttons.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx
similarity index 94%
rename from apps/web/app/deeplink/[domain]/[key]/action-buttons.tsx
rename to apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx
index 264824b51a..51e52407cc 100644
--- a/apps/web/app/deeplink/[domain]/[key]/action-buttons.tsx
+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/action-buttons.tsx
@@ -11,7 +11,7 @@ export function DeepLinkActionButtons({ link }: { link: EdgeLinkProps }) {
await copyToClipboard(link.shortLink);
}
- window.location.href = link.ios || link.url;
+ window.location.href = link.shortLink;
};
return (
diff --git a/apps/web/app/deeplink/[domain]/[key]/brand-logo-badge.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/brand-logo-badge.tsx
similarity index 94%
rename from apps/web/app/deeplink/[domain]/[key]/brand-logo-badge.tsx
rename to apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/brand-logo-badge.tsx
index 1621024f4c..5d253c4e41 100644
--- a/apps/web/app/deeplink/[domain]/[key]/brand-logo-badge.tsx
+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/brand-logo-badge.tsx
@@ -11,7 +11,7 @@ export function BrandLogoBadge({ link }: { link: EdgeLinkProps }) {
<button
onClick={async () => {
await copyToClipboard(link.shortLink);
- window.location.href = link.ios || link.url;
+ window.location.href = link.shortLink;
}}
className="inline-flex items-center gap-2 rounded-full bg-white px-3 py-1.5 shadow-lg shadow-black/10 ring-1 ring-neutral-200"
>
diff --git a/apps/web/app/deeplink/[domain]/[key]/page.tsx b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
similarity index 96%
rename from apps/web/app/deeplink/[domain]/[key]/page.tsx
rename to apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
index b2e225fc3c..fc5389bb13 100644
--- a/apps/web/app/deeplink/[domain]/[key]/page.tsx
+++ b/apps/web/app/app.dub.co/(deeplink)/deeplink/[domain]/[key]/page.tsx
@@ -3,24 +3,23 @@ import { Grid, Wordmark } from "@dub/ui";
import { ArrowRight, Copy, IOSAppStore, MobilePhone } from "@dub/ui/icons";
import { cn } from "@dub/utils";
import Link from "next/link";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
import { DeepLinkActionButtons } from "./action-buttons";
import { BrandLogoBadge } from "./brand-logo-badge";
export const runtime = "edge";
-export default async function DeepLinkPage({
+export default async function DeepLinkPreviewPage({
params,
}: {
params: { domain: string; key: string };
}) {
const domain = params.domain;
const key = decodeURIComponent(params.key);
-
const link = await getLinkViaEdge({ domain, key });
if (!link) {
- notFound();
+ redirect("/");
}
return (
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 557cf1d438..f8ed5203db 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -8,6 +8,7 @@ import {
import { recordClick } from "@/lib/tinybird";
import { formatRedisLink } from "@/lib/upstash";
import {
+ APP_DOMAIN,
DUB_HEADERS,
LEGAL_WORKSPACE_ID,
LOCALHOST_GEO_DATA,
@@ -316,7 +317,7 @@ export default async function LinkMiddleware(
cookieData,
);
- // rewrite to deeplink page if the link is a mailto: or tel:
+ // rewrite to custom-uri-scheme page if the link is a custom URI scheme
} else if (isSupportedCustomURIScheme(url)) {
ev.waitUntil(
recordClick({
@@ -424,10 +425,13 @@ export default async function LinkMiddleware(
},
}),
);
- // rewrite to the deeplink interstitial page
+
+ // redirect to the deeplink interstitial splash page "DeepLinkPreviewPage"
+ // we're doing this because the interstitial page needs to be on a different domain than the actual deep link domain
+ // @see: https://stackoverflow.com/a/78189982/10639526
return createResponseWithCookies(
- NextResponse.rewrite(
- new URL(`/deeplink/${domain}/${encodeURIComponent(key)}`, req.url),
+ NextResponse.redirect(
+ new URL(`/deeplink/${domain}/${encodeURIComponent(key)}`, APP_DOMAIN),
{
headers: {
...DUB_HEADERS,