The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Remove iframeable check on demand
Steven Teyaab3379fd568
diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.tsindex 3fb70818ee..93c69c9697 100644--- a/apps/web/lib/api/links/cache.ts+++ b/apps/web/lib/api/links/cache.ts@@ -19,7 +19,7 @@ class LinkCache {const redisLinks = await Promise.all(links.map(async (link) => ({- ...(await formatRedisLink(link)),+ ...formatRedisLink(link),key: link.key.toLowerCase(),domain: link.domain.toLowerCase(),})),@@ -40,7 +40,7 @@ class LinkCache {}async set(link: ExpandedLink) {- const redisLink = await formatRedisLink(link);+ const redisLink = formatRedisLink(link);const hasWebhooks = redisLink.webhookIds && redisLink.webhookIds.length > 0;return await redis.set(diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.tsindex f2e1235cc2..0b08a78b31 100644--- a/apps/web/lib/middleware/link.ts+++ b/apps/web/lib/middleware/link.ts@@ -90,7 +90,7 @@ export default async function LinkMiddleware(}// format link to fit the RedisLinkProps interface- link = await formatRedisLink(linkData as any);+ link = formatRedisLink(linkData as any);ev.waitUntil(linkCache.set(linkData as any));}@@ -102,7 +102,6 @@ export default async function LinkMiddleware(trackConversion,proxy,rewrite,- iframeable,expiresAt,ios,android,@@ -280,41 +279,28 @@ export default async function LinkMiddleware(}),);- if (iframeable) {- return createResponseWithCookie(- NextResponse.rewrite(- new URL(- `/cloaked/${encodeURIComponent(- getFinalUrl(url, {- req,- clickId: trackConversion ? clickId : undefined,- }),- )}`,- req.url,- ),- {- headers: {- ...DUB_HEADERS,- ...(!shouldIndex && {- "X-Robots-Tag": "googlebot: noindex",- }),- },- },+ return createResponseWithCookie(+ NextResponse.rewrite(+ new URL(+ `/cloaked/${encodeURIComponent(+ getFinalUrl(url, {+ req,+ clickId: trackConversion ? clickId : undefined,+ }),+ )}`,+ req.url,),- { clickId, path: `/${originalKey}` },- );- } else {- // if link is not iframeable, use Next.js rewrite instead- return createResponseWithCookie(- NextResponse.rewrite(url, {+ {headers: {...DUB_HEADERS,- ...(!shouldIndex && { "X-Robots-Tag": "googlebot: noindex" }),+ ...(!shouldIndex && {+ "X-Robots-Tag": "googlebot: noindex",+ }),},- }),- { clickId, path: `/${originalKey}` },- );- }+ },+ ),+ { clickId, path: `/${originalKey}` },+ );// redirect to iOS link if it is specified and the user is on an iOS device} else if (ios && userAgent(req).os?.name === "iOS") {diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex daac0287b7..2d67305daf 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -85,7 +85,6 @@ export interface RedisLinkProps {password?: boolean;proxy?: boolean;rewrite?: boolean;- iframeable?: boolean;expiresAt?: Date;expiredUrl?: string;ios?: string;diff --git a/apps/web/lib/upstash/format-redis-link.ts b/apps/web/lib/upstash/format-redis-link.tsindex 6c20c20bb5..986ba656d7 100644--- a/apps/web/lib/upstash/format-redis-link.ts+++ b/apps/web/lib/upstash/format-redis-link.ts@@ -1,13 +1,9 @@-import { isIframeable } from "@dub/utils";import { ExpandedLink } from "../api/links/utils/transform-link";import { RedisLinkProps } from "../types";-export async function formatRedisLink(- link: ExpandedLink,-): Promise<RedisLinkProps> {+export function formatRedisLink(link: ExpandedLink): RedisLinkProps {const {id,- domain,url,trackConversion,password,@@ -34,7 +30,6 @@ export async function formatRedisLink(...(url &&rewrite && {rewrite: true,- iframeable: await isIframeable({ url, requestDomain: domain }),}),...(expiresAt && { expiresAt: new Date(expiresAt) }),...(expiredUrl && { expiredUrl }),diff --git a/apps/web/scripts/update-noindex.ts b/apps/web/scripts/update-noindex.tsdeleted file mode 100644index 9db9da39e9..0000000000--- a/apps/web/scripts/update-noindex.ts+++ /dev/null@@ -1,74 +0,0 @@-// @ts-nocheck – old migration script--import { redis } from "@/lib/upstash";-import { prisma } from "@dub/prisma";-import { isIframeable } from "@dub/utils";-import "dotenv-flow/config";--async function main() {- const domains = await prisma.domain.findMany({- where: {- AND: [- {- target: {- not: null,- },- },- {- target: {- not: "",- },- },- ],- noindex: false,- },- take: 100,- });-- // const res = await Promise.all(- // domains.map(async (d) => {- // return await redis.hget(d.slug.toLowerCase(), "_root");- // }),- // );-- // console.log({ res });-- const res = await Promise.all(- domains.map(async (d) => {- const { slug: domain, id, target: url, type, projectId } = d;- const rewrite = type === "rewrite";-- return await redis- .hset(domain.toLowerCase(), {- _root: {- id,- url,- ...(url &&- rewrite && {- rewrite: true,- iframeable: await isIframeable({- url,- requestDomain: domain.toLowerCase(),- }),- }),- noindex: true,- projectId,- },- })- .then(async () => {- return await prisma.domain.update({- where: {- id,- },- data: {- noindex: true,- },- });- });- }),- );-- console.log(res);-}--main();diff --git a/apps/web/ui/modals/link-builder/options-list.tsx b/apps/web/ui/modals/link-builder/options-list.tsxindex 2a57062257..549e096a8e 100644--- a/apps/web/ui/modals/link-builder/options-list.tsx+++ b/apps/web/ui/modals/link-builder/options-list.tsx@@ -124,7 +124,7 @@ function LinkCloakingToggleBadge({) : !data ? null : data?.iframeable ? (<CheckCircleFill className="size-3.5 text-green-500" />) : (- <AlertCircleFill className="size-3.5 text-yellow-500" />+ <AlertCircleFill className="size-3.5 text-red-500" />)}/>@@ -158,22 +158,8 @@ function LinkCloakingToggleBadge({</div>) : (<span>- We will try to cloak it with{" "}- <a- href="https://nextjs.org/docs/pages/api-reference/functions/next-response#rewrite"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Next.js Rewrites- </a>- , but it might not work as expected.{" "}- <a- href="https://dub.co/help/article/link-cloaking"- target="_blank"- className="text-gray-500 underline underline-offset-2 hover:text-gray-700"- >- Learn more.- </a>+ There are some issues with the link you provided. Please try+ again.</span>)}</div>