The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
create APP_DOMAIN variable
Steven Teye9b730ff7500
diff --git a/app/api/callback/bitly/route.ts b/app/api/callback/bitly/route.tsindex aaa78c6165..fdc2e6ec8f 100644--- a/app/api/callback/bitly/route.ts+++ b/app/api/callback/bitly/route.ts@@ -1,6 +1,7 @@import { NextResponse } from "next/server";import prisma from "#/lib/prisma";import { redis } from "#/lib/upstash";+import { APP_DOMAIN } from "#/lib/constants";export async function GET(req: Request) {const { searchParams } = new URL(req.url);@@ -18,15 +19,8 @@ export async function GET(req: Request) {body: `client_id=${process.env.NEXT_PUBLIC_BITLY_CLIENT_ID}&client_secret=${process.env.BITLY_CLIENT_SECRET}&code=${code}&redirect_uri=${process.env.NEXT_PUBLIC_BITLY_REDIRECT_URI}`,}).then((r) => r.text());- const hostname =- process.env.NEXT_PUBLIC_VERCEL_ENV === "production"- ? "https://app.dub.sh"- : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"- ? "https://preview.dub.sh"- : "http://app.localhost:3000";-if (!response || response.includes("error")) {- return NextResponse.redirect(hostname);+ return NextResponse.redirect(APP_DOMAIN);}const params = new URLSearchParams(response);@@ -47,6 +41,6 @@ export async function GET(req: Request) {// redirect to project page with import query paramreturn NextResponse.redirect(- `${hostname}${project ? `/${project.slug}?import=bitly` : ""}`,+ `${APP_DOMAIN}${project ? `/${project.slug}?import=bitly` : ""}`,);}diff --git a/app/api/cron/import/route.ts b/app/api/cron/import/route.tsindex 12edb6fabc..0b92c7a18f 100644--- a/app/api/cron/import/route.ts+++ b/app/api/cron/import/route.ts@@ -13,7 +13,7 @@ const receiver = new Receiver({export async function POST(req: Request) {const body = await req.json();- if (process.env.NODE_ENV === "production") {+ if (process.env.VERCEL === "1") {const isValid = await receiver.verify({signature: req.headers.get("Upstash-Signature") || "",body: JSON.stringify(body),diff --git a/lib/constants/index.ts b/lib/constants/index.tsindex cc7d22de3c..9364249681 100644--- a/lib/constants/index.ts+++ b/lib/constants/index.ts@@ -44,6 +44,13 @@ export const APP_HOSTNAMES = new Set(["preview.dub.sh",]);+export const APP_DOMAIN =+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production"+ ? "https://app.dub.sh"+ : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"+ ? "https://preview.dub.sh"+ : "http://app.localhost:3000";+export const DEFAULT_REDIRECTS = {home: "https://dub.sh",dub: "https://dub.sh",diff --git a/pages/api/projects/[slug]/billing/manage.ts b/pages/api/projects/[slug]/billing/manage.tsindex 25ec935e7a..45f795ba77 100644--- a/pages/api/projects/[slug]/billing/manage.ts+++ b/pages/api/projects/[slug]/billing/manage.ts@@ -1,4 +1,5 @@import { withProjectAuth } from "#/lib/auth";+import { APP_DOMAIN } from "#/lib/constants";import { stripe } from "#/lib/stripe";export default withProjectAuth(async (req, res, project) => {@@ -10,11 +11,7 @@ export default withProjectAuth(async (req, res, project) => {}const { url } = await stripe.billingPortal.sessions.create({customer: project.stripeId,- return_url: `${- process.env.VERCEL === "1"- ? "https://app.dub.sh"- : "http://app.localhost:3000"- }/${slug}/settings/billing`,+ return_url: `${APP_DOMAIN}/${slug}/settings/billing`,});return res.status(200).json(url);} else {diff --git a/pages/api/projects/[slug]/billing/upgrade.ts b/pages/api/projects/[slug]/billing/upgrade.tsindex 1de26379ed..1b33021019 100644--- a/pages/api/projects/[slug]/billing/upgrade.ts+++ b/pages/api/projects/[slug]/billing/upgrade.ts@@ -1,4 +1,5 @@import { withProjectAuth } from "#/lib/auth";+import { APP_DOMAIN } from "#/lib/constants";import { stripe } from "#/lib/stripe";export default withProjectAuth(async (req, res, project, session) => {@@ -9,16 +10,8 @@ export default withProjectAuth(async (req, res, project, session) => {const stripeSession = await stripe.checkout.sessions.create({customer_email: session.user.email,billing_address_collection: "required",- success_url: `${- process.env.VERCEL === "1"- ? "https://app.dub.sh"- : "http://app.localhost:3000"- }/${slug}/settings/billing?success=true`,- cancel_url: `${- process.env.VERCEL === "1"- ? "https://app.dub.sh"- : "http://app.localhost:3000"- }/${slug}/settings/billing`,+ success_url: `${APP_DOMAIN}/${slug}/settings/billing?success=true`,+ cancel_url: `${APP_DOMAIN}/${slug}/settings/billing`,line_items: [{ price: priceId, quantity: 1 }],automatic_tax: {enabled: true,diff --git a/pages/api/projects/[slug]/import/bitly.ts b/pages/api/projects/[slug]/import/bitly.tsindex c23756c76b..8b279cd204 100644--- a/pages/api/projects/[slug]/import/bitly.ts+++ b/pages/api/projects/[slug]/import/bitly.ts@@ -92,13 +92,20 @@ export default withProjectAuth(async (req, res, project) => {return result;}, []);+ const hostname =+ process.env.NEXT_PUBLIC_VERCEL_ENV === "production"+ ? "https://app.dub.sh"+ : process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"+ ? "https://preview.dub.sh"+ : "https://067b-2600-1700-b5e4-b50-8197-b987-5375-e928.ngrok-free.app";+const response = await Promise.all(groups// only add groups that have at least 1 domain selected for import.filter(({ domains }) => domains.length > 0).map(({ bitlyGroup, domains, keepTags }) =>qstash.publishJSON({- url: "https://preview.dub.sh/api/cron/import",+ url: `${hostname}/api/cron/import`,body: {provider: "bitly",projectId: project.id,