The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
prevent undefined ip
Steven Teye3cf40458308
diff --git a/apps/web/app/(ee)/api/track/open/route.ts b/apps/web/app/(ee)/api/track/open/route.tsindex 95a77c1c6d..ad4fa1f884 100644--- a/apps/web/app/(ee)/api/track/open/route.ts+++ b/apps/web/app/(ee)/api/track/open/route.ts@@ -54,25 +54,32 @@ export const POST = withAxiom(async (req: AxiomRequest) => {await parseRequestBody(req),);- if (!deepLinkUrl) {- const ip = ipAddress(req);- console.log(`Checking cache for ${ip}:${dubDomain}:*`);-- // Get all iOS click cache keys for this identity hash- const [_, cacheKeysForDomain] = await redis.scan(0, {- match: `deepLinkClickCache:${ip}:${dubDomain}:*`,- count: 10,- });+ const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;- if (cacheKeysForDomain.length > 0) {- const cachedData = await redis.get<DeepLinkClickData>(- cacheKeysForDomain[0],- );+ if (!deepLinkUrl) {+ if (ip) {+ // if ip address is present, check if there's a cached click+ console.log(`Checking cache for ${ip}:${dubDomain}:*`);++ // Get all iOS click cache keys for this identity hash+ const [_, cacheKeysForDomain] = await redis.scan(0, {+ match: `deepLinkClickCache:${ip}:${dubDomain}:*`,+ count: 10,+ });- if (cachedData) {- return NextResponse.json(trackOpenResponseSchema.parse(cachedData), {- headers: CORS_HEADERS,- });+ if (cacheKeysForDomain.length > 0) {+ const cachedData = await redis.get<DeepLinkClickData>(+ cacheKeysForDomain[0],+ );++ if (cachedData) {+ return NextResponse.json(+ trackOpenResponseSchema.parse(cachedData),+ {+ headers: CORS_HEADERS,+ },+ );+ }}}@@ -90,8 +97,6 @@ export const POST = withAxiom(async (req: AxiomRequest) => {const domain = deepLink.hostname.replace(/^www\./, "").toLowerCase();const key = deepLink.pathname.slice(1) || "_root"; // Remove leading slash, default to _root if empty- const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;-let [cachedClickId, cachedLink] = await redis.mget<[string, RedisLinkProps, string[]]>([diff --git a/apps/web/lib/middleware/utils/cache-deeplink-click-data.ts b/apps/web/lib/middleware/utils/cache-deeplink-click-data.tsindex 61c9cf94a6..10d05fb6d7 100644--- a/apps/web/lib/middleware/utils/cache-deeplink-click-data.ts+++ b/apps/web/lib/middleware/utils/cache-deeplink-click-data.ts@@ -16,6 +16,10 @@ export async function cacheDeepLinkClickData({link: { id: string; domain: string; key: string; url: string };}) {const ip = ipAddress(req);+ if (!ip) {+ return; // skip caching if ip address is not present+ }+return await redis.set<DeepLinkClickData>(`deepLinkClickCache:${ip}:${link.domain}:${link.key}`,{