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.

Multiple default domains

Steven Teyd1e52b262a0c
diff --git a/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts b/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts
index cc2f794f37..c33af4b952 100644
--- a/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts
+++ b/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts
@@ -24,6 +24,7 @@ export const GET = withAuth(async ({ domain }) => {
primary: true,
target: true,
type: true,
+ placeholder: true,
clicks: true,
},
});
@@ -38,7 +39,13 @@ export const GET = withAuth(async ({ domain }) => {
// PUT /api/projects/[slug]/domains/[domain] – edit a project's domain
export const PUT = withAuth(async ({ req, project, domain }) => {
- const { slug: newDomain, target, type, primary } = await req.json();
+ const {
+ slug: newDomain,
+ target,
+ type,
+ placeholder,
+ primary,
+ } = await req.json();
if (newDomain !== domain) {
const validDomain = await validateDomain(newDomain);
@@ -113,6 +120,7 @@ export const PUT = withAuth(async ({ req, project, domain }) => {
target: null,
})),
type,
+ placeholder,
primary,
},
}),
diff --git a/apps/web/app/api/projects/[slug]/domains/route.ts b/apps/web/app/api/projects/[slug]/domains/route.ts
index 54b7400506..8f013fa903 100644
--- a/apps/web/app/api/projects/[slug]/domains/route.ts
+++ b/apps/web/app/api/projects/[slug]/domains/route.ts
@@ -19,6 +19,7 @@ export const GET = withAuth(async ({ project }) => {
primary: true,
target: true,
type: true,
+ placeholder: true,
clicks: true,
},
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/analytics/client.tsx b/apps/web/app/app.dub.co/(dashboard)/analytics/client.tsx
index f00a159acf..d8d08a971c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/analytics/client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/analytics/client.tsx
@@ -2,7 +2,7 @@
import LayoutLoader from "@/ui/layout/layout-loader";
import LinkNotFound from "@/ui/links/link-not-found";
-import { fetcher } from "@dub/utils";
+import { DUB_DOMAINS, fetcher } from "@dub/utils";
import { useSession } from "next-auth/react";
import { useParams, useSearchParams } from "next/navigation";
import { ReactNode } from "react";
@@ -13,7 +13,7 @@ export default function AnalyticsClient({ children }: { children: ReactNode }) {
const domain = searchParams?.get("domain");
const key = searchParams?.get("key");
- if (domain !== "dub.sh" || !key) {
+ if (!domain || !DUB_DOMAINS.find((d) => d.slug === domain) || !key) {
return <LinkNotFound />;
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/links/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/links/page-client.tsx
index f84659293c..ab4d992b0d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/links/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/links/page-client.tsx
@@ -4,7 +4,7 @@ import LinksContainer from "@/ui/links/links-container";
import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";
import { MaxWidthWrapper } from "@dub/ui";
-export default function DubLinksClient() {
+export default function LinksClient() {
const { AddEditLinkModal, AddEditLinkButton } = useAddEditLinkModal();
return (
@@ -13,7 +13,7 @@ export default function DubLinksClient() {
<div className="flex h-36 items-center border-b border-gray-200 bg-white">
<MaxWidthWrapper>
<div className="flex items-center justify-between">
- <h1 className="text-2xl text-gray-600">My Dub.sh Links</h1>
+ <h1 className="text-2xl text-gray-600">My Links</h1>
<AddEditLinkButton />
</div>
</MaxWidthWrapper>
diff --git a/apps/web/app/app.dub.co/(dashboard)/links/page.tsx b/apps/web/app/app.dub.co/(dashboard)/links/page.tsx
index 6126f7f5c4..afecaf5a80 100644
--- a/apps/web/app/app.dub.co/(dashboard)/links/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/links/page.tsx
@@ -1,5 +1,5 @@
-import DubLinksClient from "./page-client";
+import LinksClient from "./page-client";
-export default function DubLinks() {
- return <DubLinksClient />;
+export default function Links() {
+ return <LinksClient />;
}
diff --git a/apps/web/app/inspect/[domain]/[key]/page.tsx b/apps/web/app/inspect/[domain]/[key]/page.tsx
index 794ae80312..1d6c7fa98c 100644
--- a/apps/web/app/inspect/[domain]/[key]/page.tsx
+++ b/apps/web/app/inspect/[domain]/[key]/page.tsx
@@ -1,8 +1,15 @@
import { getLinkViaEdge } from "@/lib/planetscale";
-import { Background, Footer, LinkPreview, Nav } from "@dub/ui";
+import {
+ Background,
+ Footer,
+ LinkPreview,
+ LinkPreviewPlaceholder,
+ Nav,
+} from "@dub/ui";
import { HOME_DOMAIN, constructMetadata } from "@dub/utils";
import { notFound } from "next/navigation";
import LinkInspectorCard from "./card";
+import { Suspense } from "react";
export const runtime = "edge";
@@ -58,7 +65,9 @@ export default async function InspectPage({
</h2>
<LinkInspectorCard domain={domain} _key={key} url={data.url} />
- <LinkPreview defaultUrl={data.url} />
+ <Suspense fallback={<LinkPreviewPlaceholder />}>
+ <LinkPreview defaultUrl={data.url} />
+ </Suspense>
<a
href={`${HOME_DOMAIN}/tools/inspector`}
rel="noreferrer"
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 9548c9ace9..a5a5b63063 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -7,7 +7,9 @@ import prisma from "@/lib/prisma";
import { redis } from "@/lib/upstash";
import {
DEFAULT_REDIRECTS,
+ DUB_DOMAINS,
DUB_PROJECT_ID,
+ getDomainWithoutWWW,
getParamsFromURL,
nanoid,
truncate,
@@ -234,15 +236,8 @@ export async function processLink({
status: 403,
};
}
- // if it's not a custom project, do some filtering
} else {
- if (domain !== "dub.sh") {
- return {
- link: payload,
- error: "Invalid domain",
- status: 403,
- };
- }
+ // if it's not a custom project, do some filtering
if (key.includes("/")) {
return {
link: payload,
@@ -251,26 +246,47 @@ export async function processLink({
status: 422,
};
}
- const keyBlacklisted = await isBlacklistedKey(key);
- if (keyBlacklisted) {
- return {
- link: payload,
- error: "Invalid key.",
- status: 422,
- };
- }
- const domainBlacklisted = await isBlacklistedDomain(url);
- if (domainBlacklisted) {
+ if (rewrite) {
return {
link: payload,
- error: "Invalid url.",
- status: 422,
+ error: "You can only use link cloaking on a custom domain.",
+ status: 403,
};
}
- if (rewrite) {
+ if (domain === "dub.sh") {
+ const keyBlacklisted = await isBlacklistedKey(key);
+ if (keyBlacklisted) {
+ return {
+ link: payload,
+ error: "Invalid key.",
+ status: 422,
+ };
+ }
+ const domainBlacklisted = await isBlacklistedDomain(url);
+ if (domainBlacklisted) {
+ return {
+ link: payload,
+ error: "Invalid url.",
+ status: 422,
+ };
+ }
+ } else if (DUB_DOMAINS.find((d) => d.slug === domain)) {
+ // coerce type with ! cause we already checked if it exists
+ const { allowedHostnames } = DUB_DOMAINS.find((d) => d.slug === domain)!;
+ const urlDomain = getDomainWithoutWWW(url) || "";
+ if (!allowedHostnames.includes(urlDomain)) {
+ return {
+ link: payload,
+ error: `Invalid url. You can only use ${domain} short links for URLs starting with ${allowedHostnames
+ .map((d) => `\`${d}\``)
+ .join(", ")}.`,
+ status: 422,
+ };
+ }
+ } else {
return {
link: payload,
- error: "You can only use link cloaking on a custom domain.",
+ error: "Invalid domain",
status: 403,
};
}
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index be9a078950..d1336d645f 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -4,7 +4,7 @@ import { Link as LinkProps } from "@prisma/client";
import { PlanProps, ProjectProps } from "../types";
import { getServerSession } from "next-auth/next";
import { createHash } from "crypto";
-import { API_DOMAIN, getSearchParams } from "@dub/utils";
+import { API_DOMAIN, DUB_DOMAINS, getSearchParams } from "@dub/utils";
import { ratelimit } from "../upstash";
export interface Session {
@@ -303,9 +303,9 @@ export const withAuth =
headers,
});
}
- // for generic dub.sh links / stats
+ // for generic DUB_DOMAINS links / stats
} else {
- if (domain && domain !== "dub.sh") {
+ if (domain && !DUB_DOMAINS.find((d) => d.slug === domain)) {
return new Response("Domain not found.", {
status: 404,
headers,
@@ -322,8 +322,11 @@ export const withAuth =
});
}
- // if it's the default dub.sh link, we need to make sure the user is the owner of the link
- if (link.domain === "dub.sh" && link.userId !== session.user.id) {
+ // if it's generic DUB_DOMAINS links, we need to make sure the user is the owner of the link
+ if (
+ DUB_DOMAINS.find((d) => d.slug === link.domain) &&
+ link.userId !== session.user.id
+ ) {
return new Response("Unauthorized: Invalid link.", {
status: 403,
headers,
diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.ts
index 5318c5f804..7357c3b054 100644
--- a/apps/web/lib/swr/use-domains.ts
+++ b/apps/web/lib/swr/use-domains.ts
@@ -1,5 +1,5 @@
import { DomainProps } from "@/lib/types";
-import { fetcher } from "@dub/utils";
+import { DUB_DOMAINS, fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
import { useMemo } from "react";
import useSWR from "swr";
@@ -18,18 +18,8 @@ export default function useDomains({ domain }: { domain?: string } = {}) {
);
const domains = useMemo(() => {
- return slug
- ? data
- : ([
- {
- slug: "dub.sh",
- verified: true,
- primary: true,
- target: "https://dub.co",
- type: "redirect",
- },
- ] as DomainProps[]);
- }, [data]);
+ return slug ? data : DUB_DOMAINS;
+ }, [slug, data]) as DomainProps[];
return {
domains,
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index b4c7a319ed..661794ab12 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -71,6 +71,7 @@ export interface DomainProps {
primary: boolean;
target?: string;
type: "redirect" | "rewrite";
+ placeholder?: string;
clicks: number;
}
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 7fa7db07f3..a6c8bcbdbc 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -23,7 +23,7 @@ model User {
sessions Session[]
projects ProjectUsers[]
links Link[]
- tokens Token[]
+ tokens Token[]
createdAt DateTime @default(now())
}
@@ -157,6 +157,7 @@ model Domain {
verified Boolean @default(false)
target String?
type String @default("redirect")
+ placeholder String @default("https://dub.co/help/article/what-is-dub")
description String?
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
projectId String?
@@ -171,7 +172,7 @@ model Domain {
@@index(projectId)
@@index(clicks(sort: Desc))
@@index(lastClicked)
- @@index(lastChecked)
+ @@index(lastChecked(sort: Asc))
}
model Link {
@@ -213,12 +214,13 @@ model Link {
// Relational reference to the project domain
projectDomain Domain? @relation(fields: [domain], references: [slug], onUpdate: Cascade, onDelete: Cascade)
- publicStats Boolean @default(false) // whether to show public stats or not
- clicks Int @default(0) // number of clicks
- lastClicked DateTime? // when the link was last clicked
- lastChecked DateTime? // when the link was last checked for 404s
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ publicStats Boolean @default(false) // whether to show public stats or not
+ clicks Int @default(0) // number of clicks
+ lastClicked DateTime? // when the link was last clicked
+ checkDisabled Boolean @default(false) // disable 404 checking
+ lastChecked DateTime? // when the link was last checked for 404s
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
// Link tags
tag Tag? @relation(fields: [tagId], references: [id])
@@ -238,7 +240,8 @@ model Link {
@@index(createdAt(sort: Desc))
@@index(clicks(sort: Desc))
@@index(lastClicked)
- @@index(lastChecked)
+ @@index(checkDisabled)
+ @@index(lastChecked(sort: Asc))
@@index(userId)
@@fulltext([key, url])
}
diff --git a/apps/web/ui/layout/nav-tabs.tsx b/apps/web/ui/layout/nav-tabs.tsx
index cb218cb151..d945d01028 100644
--- a/apps/web/ui/layout/nav-tabs.tsx
+++ b/apps/web/ui/layout/nav-tabs.tsx
@@ -31,7 +31,7 @@ export default function NavTabs() {
}
return [
{ name: "Projects", href: "/" },
- { name: "Dub.sh Links", href: "/links" },
+ { name: "Links", href: "/links" },
{ name: "Settings", href: "/settings" },
];
}, [pathname, slug, searchParams]);
diff --git a/apps/web/ui/modals/add-edit-domain-modal.tsx b/apps/web/ui/modals/add-edit-domain-modal.tsx
index 3c840df923..5a0c95c390 100644
--- a/apps/web/ui/modals/add-edit-domain-modal.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal.tsx
@@ -3,7 +3,16 @@ import { DomainProps } from "@/lib/types";
import { ModalContext } from "@/ui/modals/provider";
import { BlurImage } from "@/ui/shared/blur-image";
import { AlertCircleFill, Lock } from "@/ui/shared/icons";
-import { Button, Logo, Modal, Switch, Tooltip, TooltipContent } from "@dub/ui";
+import {
+ Button,
+ InfoTooltip,
+ Logo,
+ Modal,
+ SimpleTooltipContent,
+ Switch,
+ Tooltip,
+ TooltipContent,
+} from "@dub/ui";
import { SWIPE_REVEAL_ANIMATION_SETTINGS } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import { useParams, useRouter } from "next/navigation";
@@ -45,7 +54,7 @@ function AddEditDomainModal({
},
);
- const { slug: domain, primary, target, type } = data;
+ const { slug: domain, primary, target, type, placeholder } = data;
const [debouncedDomain] = useDebounce(domain, 500);
useEffect(() => {
@@ -145,7 +154,7 @@ function AddEditDomainModal({
) : (
<Logo />
)}
- <h3 className="text-lg font-medium">{props ? "Edit" : "Add"} Domain</h3>
+ <h1 className="text-lg font-medium">{props ? "Edit" : "Add"} Domain</h1>
</div>
<form
@@ -180,11 +189,8 @@ function AddEditDomainModal({
>
<div>
<div className="flex items-center justify-between">
- <label
- htmlFor="domain"
- className="block text-sm font-medium text-gray-700"
- >
- Domain
+ <label htmlFor="domain">
+ <h2 className="text-sm font-medium text-gray-700">Domain</h2>
</label>
{props && lockDomain && (
<button
@@ -259,11 +265,9 @@ function AddEditDomainModal({
</div>
<div>
- <label
- htmlFor="target"
- className="block text-sm font-medium text-gray-700"
- >
- Landing Page
+ <label htmlFor="target" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Landing Page</h2>
+ <InfoTooltip content="The page your users will get redirected to when they visit your domain." />
</label>
{plan !== "free" ? (
<div className="relative mt-1 rounded-md shadow-sm">
@@ -324,8 +328,35 @@ function AddEditDomainModal({
)}
</AnimatePresence>
+ <div>
+ <label htmlFor="placeholder" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Input Placeholder URL
+ </h2>
+ <InfoTooltip content="Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened." />
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="url"
+ name="placeholder"
+ id="placeholder"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ placeholder="https://dub.co/help/article/what-is-dub"
+ value={placeholder}
+ onChange={(e) =>
+ setData({ ...data, placeholder: e.target.value })
+ }
+ />
+ </div>
+ </div>
+
<div className="flex items-center justify-between bg-gray-50">
- <p className="text-sm font-medium text-gray-900">Primary Domain</p>
+ <div className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Primary Domain
+ </h2>
+ <InfoTooltip content="The default domain used in the link creation modal. You can only have one primary domain at a time." />
+ </div>
<Switch
fn={() => setData((prev) => ({ ...prev, primary: !primary }))}
checked={primary}
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index 996820ab76..693108c5f1 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -74,7 +74,6 @@ function AddEditLinkModal({
}) {
const params = useParams() as { slug?: string };
const { slug } = params;
- const searchParams = useSearchParams();
const router = useRouter();
const pathname = usePathname();
@@ -415,7 +414,10 @@ function AddEditLinkModal({
id={`url-${randomIdx}`}
type="url"
required
- placeholder="https://github.com/steven-tey/dub"
+ placeholder={
+ domains?.find(({ slug }) => slug === domain)
+ ?.placeholder || "https://dub.co/help/article/what-is-dub"
+ }
value={url}
autoFocus={!key}
autoComplete="off"
diff --git a/apps/web/ui/modals/delete-account-modal.tsx b/apps/web/ui/modals/delete-account-modal.tsx
index 7d0f90bdb7..cba0e4b498 100644
--- a/apps/web/ui/modals/delete-account-modal.tsx
+++ b/apps/web/ui/modals/delete-account-modal.tsx
@@ -55,8 +55,8 @@ function DeleteAccountModal({
<Avatar user={session?.user} />
<h3 className="text-lg font-medium">Delete Account</h3>
<p className="text-center text-sm text-gray-500">
- Warning: This will permanently delete your account and all your Dub.sh
- links and their respective stats.
+ Warning: This will permanently delete your account, all your projects,
+ and all your short links.
</p>
</div>
diff --git a/apps/web/ui/projects/no-projects-placeholder.tsx b/apps/web/ui/projects/no-projects-placeholder.tsx
index 002b51e786..f53dd9898f 100644
--- a/apps/web/ui/projects/no-projects-placeholder.tsx
+++ b/apps/web/ui/projects/no-projects-placeholder.tsx
@@ -30,7 +30,7 @@ export default function NoProjectsPlaceholder() {
href="/links"
className="mt-3 text-sm font-medium text-gray-500 transition-all hover:text-gray-800 active:scale-95"
>
- Add a Dub.sh link instead
+ Create a short link instead
</Link>
</div>
);
diff --git a/apps/web/ui/stats/index.tsx b/apps/web/ui/stats/index.tsx
index 19a19b9433..ace1d8a70d 100644
--- a/apps/web/ui/stats/index.tsx
+++ b/apps/web/ui/stats/index.tsx
@@ -73,12 +73,12 @@ export default function Stats({
baseApiPath: `/api/projects/${slug}/stats`,
domain: domainSlug,
};
- // Generic Dub.sh links analytics page, e.g. app.dub.co/analytics?domain=dub.sh&key=github
+ // Generic links analytics page, e.g. app.dub.co/analytics?domain=dub.sh&key=github
} else if (pathname === "/analytics") {
return {
basePath: `/analytics`,
baseApiPath: `/api/stats`,
- domain: "dub.sh",
+ domain: domainSlug,
};
}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index f990731445..5eac2979ac 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub.co",
- "version": "0.0.20",
+ "version": "0.0.21",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/packages/ui/src/link-preview.tsx b/packages/ui/src/link-preview.tsx
index d8fda937be..579136360a 100644
--- a/packages/ui/src/link-preview.tsx
+++ b/packages/ui/src/link-preview.tsx
@@ -109,3 +109,31 @@ export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
</>
);
}
+
+export function LinkPreviewPlaceholder({
+ defaultUrl,
+}: {
+ defaultUrl?: string;
+}) {
+ return (
+ <>
+ <div className="relative flex items-center">
+ <Link2 className="absolute inset-y-0 left-0 my-2 ml-3 w-5 text-gray-400" />
+ <input
+ name="url"
+ id="url"
+ type="url"
+ disabled
+ className="block w-full rounded-md border-gray-200 pl-10 text-sm text-gray-900 placeholder-gray-400 shadow-lg focus:border-gray-500 focus:outline-none focus:ring-gray-500"
+ placeholder="Enter your URL"
+ defaultValue={defaultUrl || "https://github.com/steven-tey/dub"}
+ />
+ </div>
+ <div className="relative overflow-hidden rounded-md border border-gray-300 bg-gray-50">
+ <div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-gray-300 bg-gray-50">
+ <LoadingCircle />
+ </div>
+ </div>
+ </>
+ );
+}
diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.ts
index 7259eb6ef7..8a917e39c6 100644
--- a/packages/utils/src/constants/index.ts
+++ b/packages/utils/src/constants/index.ts
@@ -117,6 +117,29 @@ export const SHOW_BACKGROUND_SEGMENTS = [
"auth",
];
+export const DUB_DOMAINS = [
+ {
+ slug: "dub.sh",
+ verified: true,
+ primary: true,
+ target: "https://dub.co",
+ type: "redirect",
+ placeholder: "https://dub.co/help/article/what-is-dub",
+ clicks: 0,
+ allowedHostnames: [],
+ },
+ {
+ slug: "chatg.pt",
+ verified: true,
+ primary: false,
+ target: "https://dub.co/tools/chatgpt-link-shortener",
+ type: "redirect",
+ placeholder: "https://chat.openai.com/g/g-UGjKKONEe-domainsgpt",
+ clicks: 0,
+ allowedHostnames: ["chat.openai.com"],
+ },
+];
+
export const ALL_TOOLS = [
{ name: "Metatags API", slug: "metatags" },
{ name: "QR Code Generator", slug: "qr-code" },