The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
STORAGE_DOMAIN to STORAGE_BASE_URL
Zach Waterfield2e2d8f6ce8c1
diff --git a/apps/docs/self-hosting.mdx b/apps/docs/self-hosting.mdxindex 8f35962840..acc3aedc87 100644--- a/apps/docs/self-hosting.mdx+++ b/apps/docs/self-hosting.mdx@@ -341,10 +341,10 @@ To use your own domain, you'll need to create a CNAME record in your DNS settingIn you plan to use an R2.dev subdomain, make sure you "Allow Access".-Then set the `STORAGE_DOMAIN` in your `.env` file to the domain you chose.+Then set the `STORAGE_BASE_URL` in your `.env` file to the domain you chose.```bash-STORAGE_DOMAIN={Your Domain}+STORAGE_BASE_URL={URL your assets as available at} # https://static.example.copm```<Frame></Frame>diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex f47004de36..024d77c674 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -84,7 +84,7 @@ UNSPLASH_ACCESS_KEY=STORAGE_ACCESS_KEY_ID=STORAGE_SECRET_ACCESS_KEY=STORAGE_ENDPOINT=-STORAGE_DOMAIN=+STORAGE_BASE_URL=# Used for internal monitoring & paging# You can remove this by removing `DUB_SLACK_HOOK_CRON` and `DUB_SLACK_HOOK_LINKS` from the codebasediff --git a/apps/web/app/api/admin/ban/route.ts b/apps/web/app/api/admin/ban/route.tsindex 4b6704e1f5..700e9d0b5d 100644--- a/apps/web/app/api/admin/ban/route.ts+++ b/apps/web/app/api/admin/ban/route.ts@@ -60,7 +60,7 @@ export const POST = withAdmin(async ({ req }) => {},}),// if the user has a custom avatar, delete it- user.image?.startsWith(`https://${process.env.STORAGE_DOMAIN}`) &&+ user.image?.startsWith(process.env.STORAGE_BASE_URL as string) &&storage.delete(`avatars/${user.id}`),unsubscribe(user.email),fetch(diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.tsindex 646fb9fd46..1f15d646ab 100644--- a/apps/web/app/api/user/route.ts+++ b/apps/web/app/api/user/route.ts@@ -81,7 +81,7 @@ export const DELETE = withSession(async ({ session }) => {});const response = await Promise.allSettled([// if the user has a custom avatar, delete it- user.image?.startsWith(`https://${process.env.STORAGE_DOMAIN}`) &&+ user.image?.startsWith(process.env.STORAGE_BASE_URL as string) &&storage.delete(`avatars/${session.user.id}`),unsubscribe(session.user.email),]);diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 8fa485208b..68c106f7df 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -552,7 +552,7 @@ export async function addLink(link: LinkWithTagIdsProps) {},});- const uploadedImageUrl = `https://${process.env.STORAGE_DOMAIN}/images/${response.id}`;+ const uploadedImageUrl = `${process.env.STORAGE_BASE_URL}/images/${response.id}`;if (proxy && image && uploadedImage) {await Promise.all([@@ -752,7 +752,7 @@ export async function editLink({await storage.upload(`images/${id}`, image);}// if there's an image in R2, delete it- } else if (oldImage?.startsWith(`https://${process.env.STORAGE_DOMAIN}`)) {+ } else if (oldImage?.startsWith(process.env.STORAGE_BASE_URL as string)) {await storage.delete(`images/${id}`);}@@ -767,7 +767,7 @@ export async function editLink({title: truncate(title, 120),description: truncate(description, 240),image: uploadedImage- ? `https://${process.env.STORAGE_DOMAIN}/images/${id}`+ ? `${process.env.STORAGE_BASE_URL}/images/${id}`: image,utm_source,utm_medium,@@ -835,7 +835,7 @@ export async function deleteLink(linkId: string) {return await Promise.allSettled([// if the image is stored in Cloudflare R2, delete itlink.proxy &&- link.image?.startsWith(`https://${process.env.STORAGE_DOMAIN}`) &&+ link.image?.startsWith(process.env.STORAGE_BASE_URL as string) &&storage.delete(`images/${link.id}`),redis.hdel(link.domain, link.key.toLowerCase()),recordLink({ link, deleted: true }),diff --git a/apps/web/lib/api/projects.ts b/apps/web/lib/api/projects.tsindex 51726dde12..f69fdd0f91 100644--- a/apps/web/lib/api/projects.ts+++ b/apps/web/lib/api/projects.ts@@ -63,7 +63,7 @@ export async function deleteProject(pipeline.exec(),// remove all images from R2...defaultDomainLinks.map(({ id, proxy, image }) =>- proxy && image?.startsWith(`https://${process.env.STORAGE_DOMAIN}`)+ proxy && image?.startsWith(process.env.STORAGE_BASE_URL as string)? storage.delete(`images/${id}`): Promise.resolve(),),@@ -71,7 +71,7 @@ export async function deleteProject(const deleteProjectResponse = await Promise.all([// delete project logo if it's a custom logo stored in R2- project.logo?.startsWith(`https://${process.env.STORAGE_DOMAIN}`) &&+ project.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&storage.delete(`logos/${project.id}`),// if they have a Stripe subscription, cancel itproject.stripeId && cancelSubscription(project.stripeId),@@ -127,7 +127,7 @@ export async function deleteProjectAdmin(const deleteProjectResponse = await Promise.all([// delete project logo if it's a custom logo stored in R2- project.logo?.startsWith(`https://${process.env.STORAGE_DOMAIN}`) &&+ project.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&storage.delete(`logos/${project.id}`),// if they have a Stripe subscription, cancel itproject.stripeId && cancelSubscription(project.stripeId),diff --git a/apps/web/lib/storage.ts b/apps/web/lib/storage.tsindex f3145c902e..e72a67786c 100644--- a/apps/web/lib/storage.ts+++ b/apps/web/lib/storage.ts@@ -41,7 +41,7 @@ class StorageClient {});return {- url: `${process.env.STORAGE_DOMAIN}/${key}`,+ url: `${process.env.STORAGE_BASE_URL}/${key}`,};}