The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix domain bugs, improved cloudflare domains docs
Steven Tey908dd40441c9
diff --git a/components/app/modals/add-edit-domain-modal.tsx b/components/app/modals/add-edit-domain-modal.tsxindex 210d936e85..1a53593686 100644--- a/components/app/modals/add-edit-domain-modal.tsx+++ b/components/app/modals/add-edit-domain-modal.tsx@@ -167,9 +167,11 @@ function AddEditDomainModal({const { domainError: domainErrorResponse } = await res.json();if (domainErrorResponse) {setDomainError(domainErrorResponse);+ toast.error(domainErrorResponse);}} else {setDomainError("Something went wrong. Please try again.");+ toast.error("Something went wrong. Please try again.");}});}}diff --git a/content/help/using-cloudflare-domains.mdx b/content/help/using-cloudflare-domains.mdxindex 2886af9db3..c05c7dbf39 100644--- a/content/help/using-cloudflare-domains.mdx+++ b/content/help/using-cloudflare-domains.mdx@@ -21,10 +21,17 @@ If you're using a domain on Cloudflare for your Dub project, you might need to cIf you're using Cloudflare's proxy for your custom domain, you'll need to make sure that your SSL/TLS encryption mode is set to "Full" on Cloudflare.+<Image+ alt="Using Cloudflare's proxy for your custom domain"+ src="https://d2vwwcvoksz7ty.cloudfront.net/help/cloudflare-with-proxy.png"+ width={1304}+ height={372}+/>+You can do that by following these steps:1. Go to your Cloudflare dashboard and select your domain.-2. Click on the **SSL/TLS** tab.+2. Click on the **SSL/TLS** tab on the sidebar menu.3. Under **Overview**, select the **Full** option.<Image@@ -42,9 +49,9 @@ If you're only using Cloudflare's DNS for your custom domain, all you need to do<Imagealt={`Set your domain's Proxy status to "DNS only" on Cloudflare (greyed out cloud icon)`}- src="https://d2vwwcvoksz7ty.cloudfront.net/help/cloudflare-dns-only.png"- width={3634}- height={1052}+ src="https://d2vwwcvoksz7ty.cloudfront.net/help/cloudflare-without-proxy.png"+ width={1304}+ height={372}/>This will make sure that the traffic to your domain is _not proxied through Cloudflare_ and is sent directly to Dub. You can learn more about Cloudflare's proxy options [here](https://support.cloudflare.com/hc/en-us/articles/200169626-Identifying-network-ports-compatible-with-Cloudflare-s-proxy).diff --git a/lib/api/domains.ts b/lib/api/domains.tsindex b01fa7bd62..1a33539631 100644--- a/lib/api/domains.ts+++ b/lib/api/domains.ts@@ -229,7 +229,13 @@ export async function changeDomainForImages(domain: string, newDomain: string) {}/* Delete a domain and all links & images associated with with */-export async function deleteDomainAndLinks(domain: string) {+export async function deleteDomainAndLinks(+ domain: string,+ {+ // Note: in certain cases, we don't need to remove the domain from the Prisma+ skipPrismaDelete = false,+ } = {},+) {const links = await prisma.link.findMany({where: {domain,@@ -246,6 +252,11 @@ export async function deleteDomainAndLinks(domain: string) {cloudinary.v2.api.delete_resources_by_prefix(domain),// remove the domain from VercelremoveDomainFromVercel(domain),- // Note: no need to remove the domain from the Prisma since we have onDelte: CASCADE+ !skipPrismaDelete &&+ prisma.domain.delete({+ where: {+ slug: domain,+ },+ }),]);}diff --git a/pages/api/projects/[slug]/domains/[domain]/index.ts b/pages/api/projects/[slug]/domains/[domain]/index.tsindex 83f217d78f..2c564fe8a4 100644--- a/pages/api/projects/[slug]/domains/[domain]/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/index.ts@@ -48,6 +48,15 @@ export default withProjectAuth(async (req, res, project) => {});}+ if (newDomain !== domain) {+ const vercelResponse = await addDomainToVercel(newDomain);+ if (vercelResponse.error) {+ return res.status(422).json({+ domainError: vercelResponse.error.message,+ });+ }+ }+const response = await Promise.allSettled([// if the domain is being changed, we need to:// 1. Remove the old domain from Vercel@@ -56,9 +65,7 @@ export default withProjectAuth(async (req, res, project) => {// 4. Update all images in the project to point to the new domain...(newDomain !== domain? [- removeDomainFromVercel(domain).then(() =>- addDomainToVercel(newDomain),- ),+ removeDomainFromVercel(domain),changeDomainForLinks(domain, newDomain),changeDomainForImages(domain, newDomain),]diff --git a/pages/api/projects/[slug]/domains/index.ts b/pages/api/projects/[slug]/domains/index.tsindex 21b6df6fc9..26d7b218c2 100644--- a/pages/api/projects/[slug]/domains/index.ts+++ b/pages/api/projects/[slug]/domains/index.ts@@ -29,6 +29,12 @@ export default withProjectAuth(async (req, res, project) => {domainError: validDomain,});}+ const vercelResponse = await addDomainToVercel(domain);+ if (vercelResponse.error) {+ return res.status(422).json({+ domainError: vercelResponse.error.message,+ });+ }/*If the domain is being added, we need to:1. Add the domain to Vercel@@ -37,7 +43,6 @@ export default withProjectAuth(async (req, res, project) => {4. Add the domain to the database along with its primary status*/const response = await Promise.allSettled([- addDomainToVercel(domain),target &&redis.set(`root:${domain}`, {target,diff --git a/pages/api/projects/[slug]/index.ts b/pages/api/projects/[slug]/index.tsindex 66a1b1a133..2d4ef57e50 100644--- a/pages/api/projects/[slug]/index.ts+++ b/pages/api/projects/[slug]/index.ts@@ -43,7 +43,12 @@ export default withProjectAuth(async (req, res, project) => {// delete all domains, links, and uploaded images associated with the projectconst deleteDomainsResponse = await Promise.allSettled(- domains.map((domain) => deleteDomainAndLinks(domain)),+ domains.map((domain) =>+ deleteDomainAndLinks(domain, {+ // here, we don't need to delete in prisma because we're deleting the project later and have onDelete: CASCADE set+ skipPrismaDelete: true,+ }),+ ),);const deleteProjectResponse = await Promise.all([