Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

smol tweaks

Steven Teyf27bc972dfe2
diff --git a/components/app/modals/add-edit-domain-modal.tsx b/components/app/modals/add-edit-domain-modal.tsx
index c12e643a3b..68553a930f 100644
--- a/components/app/modals/add-edit-domain-modal.tsx
+++ b/components/app/modals/add-edit-domain-modal.tsx
@@ -113,7 +113,6 @@ function AddEditDomainModal({
fetch(`/api/projects/${slug}/domains/${domain}`, {
method: "DELETE",
}).then(async (res) => {
- setDeleting(false);
if (res.status === 200) {
await Promise.all([
mutate(`/api/projects/${slug}/domains`),
@@ -128,6 +127,7 @@ function AddEditDomainModal({
} else {
setDomainError("Something went wrong. Please try again.");
}
+ setDeleting(false);
});
}
@@ -162,7 +162,6 @@ function AddEditDomainModal({
},
body: JSON.stringify(data),
}).then(async (res) => {
- setSaving(false);
if (res.status === 200) {
await mutate(`/api/projects/${slug}/domains`);
setShowAddEditDomainModal(false);
@@ -180,6 +179,7 @@ function AddEditDomainModal({
const error = await res.text();
toast.error(error);
}
+ setSaving(false);
});
}}
className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16"
diff --git a/lib/api/domains.ts b/lib/api/domains.ts
index 92adfd555d..2322ec6222 100644
--- a/lib/api/domains.ts
+++ b/lib/api/domains.ts
@@ -1,7 +1,11 @@
import prisma from "#/lib/prisma";
import { redis } from "#/lib/upstash";
import cloudinary from "cloudinary";
-import { getApexDomain, validDomainRegex } from "#/lib/utils";
+import {
+ getApexDomain,
+ getDomainWithoutWWW,
+ validDomainRegex,
+} from "#/lib/utils";
import { isIframeable } from "../middleware/utils";
export const validateDomain = async (
@@ -67,16 +71,26 @@ interface CustomResponse extends Response {
export const addDomainToVercel = async (
domain: string,
+ {
+ redirectToApex,
+ }: {
+ redirectToApex?: boolean;
+ } = {},
): Promise<CustomResponse> => {
return await fetch(
- `https://api.vercel.com/v9/projects/${process.env.PROJECT_ID_VERCEL}/domains?teamId=${process.env.TEAM_ID_VERCEL}`,
+ `https://api.vercel.com/v10/projects/${process.env.PROJECT_ID_VERCEL}/domains?teamId=${process.env.TEAM_ID_VERCEL}`,
{
- body: `{\n "name": "${domain}"\n}`,
+ method: "POST",
headers: {
Authorization: `Bearer ${process.env.AUTH_BEARER_TOKEN}`,
"Content-Type": "application/json",
},
- method: "POST",
+ body: JSON.stringify({
+ name: domain,
+ ...(redirectToApex && {
+ redirect: getDomainWithoutWWW(domain),
+ }),
+ }),
},
).then((res) => res.json());
};
diff --git a/package.json b/package.json
index 67fe598fda..fbff9aba4d 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"private": true,
"license": "AGPL-3.0-or-later",
"scripts": {
- "dev": "concurrently --kill-others \"next dev --port 8888\" \"prisma studio --browser none\" \"email dev --port 3333\"",
+ "dev": "concurrently --kill-others \"prisma migrate && next dev --port 8888\" \"prisma studio --browser none\" \"email dev --port 3333\"",
"build": "prisma generate & next build",
"format:write": "prettier --write \"**/*.{css,js,json,jsx,ts,tsx}\"",
"format": "prettier \"**/*.{css,js,json,jsx,ts,tsx}\"",