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.

Improved placeholder page for custom domains root page

Steven Tey7c71d62ebe80
diff --git a/components/app/welcome/interim.tsx b/components/app/welcome/interim.tsx
index fc32a8a2ed..d1702f3451 100644
--- a/components/app/welcome/interim.tsx
+++ b/components/app/welcome/interim.tsx
@@ -2,13 +2,12 @@ import { Dispatch, SetStateAction, useState } from "react";
import { motion } from "framer-motion";
import BlurImage from "@/components/shared/blur-image";
import { Logo } from "@/components/shared/icons";
+import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
export default function Interim({
setState,
- staggerChildVariants,
}: {
setState: Dispatch<SetStateAction<string>>;
- staggerChildVariants: any;
}) {
return (
<motion.div
@@ -29,7 +28,7 @@ export default function Interim({
transition={{ duration: 0.5, type: "spring" }}
>
<motion.div
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
className="flex flex-col items-center space-y-5 text-center"
>
<Logo className="h-11 w-11" />
@@ -39,7 +38,7 @@ export default function Interim({
</motion.div>
<motion.p
className="text-gray-600 transition-colors sm:text-lg"
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
>
Have your own domain? Start creating branded short links for free.{" "}
<br className="hidden sm:block" />
@@ -55,7 +54,7 @@ export default function Interim({
domain to create short links.
</motion.p>
<motion.div
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
className="grid w-full grid-cols-1 divide-y divide-gray-100 rounded-md border border-gray-200 bg-white md:grid-cols-2 md:divide-x"
>
<button
diff --git a/components/app/welcome/intro.tsx b/components/app/welcome/intro.tsx
index aace8f4382..2329c60ccd 100644
--- a/components/app/welcome/intro.tsx
+++ b/components/app/welcome/intro.tsx
@@ -2,13 +2,12 @@ import Spline from "@splinetool/react-spline";
import { Dispatch, SetStateAction, useState } from "react";
import { useDebounce } from "use-debounce";
import { motion } from "framer-motion";
+import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
export default function Intro({
setState,
- staggerChildVariants,
}: {
setState: Dispatch<SetStateAction<string>>;
- staggerChildVariants: any;
}) {
const [loading, setLoading] = useState(true);
const onLoad = () => {
@@ -51,18 +50,18 @@ export default function Intro({
>
<motion.h1
className="font-display text-4xl font-bold text-gray-800 transition-colors sm:text-5xl"
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
>
Welcome to Dub
</motion.h1>
<motion.p
className="max-w-md text-gray-600 transition-colors sm:text-lg"
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
>
Dub gives you marketing superpowers with short links that stand out.
</motion.p>
<motion.button
- variants={staggerChildVariants}
+ variants={STAGGER_CHILD_VARIANTS}
className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black"
onClick={() => setState("interim")}
>
diff --git a/components/layout/home/index.tsx b/components/layout/home/index.tsx
index 16dbdbd44f..d9fee93dcd 100644
--- a/components/layout/home/index.tsx
+++ b/components/layout/home/index.tsx
@@ -1,7 +1,7 @@
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/router";
-import { ReactNode, useEffect, useState } from "react";
+import { ReactNode } from "react";
import { useSession } from "next-auth/react";
import { Github, Logo, Twitter } from "@/components/shared/icons";
import Meta from "../meta";
@@ -22,12 +22,6 @@ export default function HomeLayout({
const { data: session, status } = useSession();
const router = useRouter();
const { key } = router.query as { key?: string };
-
- const [hostname, setHostname] = useState("dub.sh");
- useEffect(() => {
- setHostname(window.location.origin);
- }, []);
-
return (
<div className="flex min-h-screen flex-col justify-between">
<Meta {...meta} />
@@ -35,7 +29,7 @@ export default function HomeLayout({
<div className="mx-auto max-w-screen-xl px-5 md:px-20">
<div className="flex h-16 items-center justify-between">
<div className="flex items-center">
- <Link href={hostname === "dub.sh" ? "/" : `https://dub.sh/`}>
+ <Link href="/">
<Image
src="/_static/logotype.svg"
alt="Dub.sh logo"
@@ -69,12 +63,12 @@ export default function HomeLayout({
</div>
</div>
{children}
- <div className="z-10 flex h-20 items-center justify-center space-x-12 border-t border-gray-200">
+ <div className="z-10 flex h-20 items-center justify-center space-x-12 border-t border-gray-200 bg-white">
<a href="https://twitter.com/dubdotsh" target="_blank" rel="noreferrer">
<span className="sr-only">Twitter</span>
<Twitter className="h-6 w-6 text-gray-600" />
</a>
- <Link href={hostname === "https://dub.sh" ? "/" : `https://dub.sh/`}>
+ <Link href="/">
<span className="sr-only">Dub.sh Logo</span>
<Logo className="h-7 w-7 text-gray-600" />
</Link>
diff --git a/lib/constants/index.ts b/lib/constants/index.ts
index 51e057747a..6d711effc8 100644
--- a/lib/constants/index.ts
+++ b/lib/constants/index.ts
@@ -34,6 +34,11 @@ export const FRAMER_MOTION_LIST_ITEM_VARIANTS = {
show: { scale: 1, opacity: 1, transition: { type: "spring" } },
};
+export const STAGGER_CHILD_VARIANTS = {
+ hidden: { opacity: 0, y: 20 },
+ show: { opacity: 1, y: 0, transition: { duration: 0.4, type: "spring" } },
+};
+
export const SWIPE_REVEAL_ANIMATION_SETTINGS = {
initial: { height: 0 },
animate: { height: "auto" },
@@ -64,7 +69,6 @@ export const RESERVED_KEYS = new Set([
"auth",
"pricing",
"about",
- "placeholder",
"metatags",
"blog",
"careers",
diff --git a/lib/middleware/root.ts b/lib/middleware/root.ts
index 28673c4c6a..59039276cc 100644
--- a/lib/middleware/root.ts
+++ b/lib/middleware/root.ts
@@ -30,7 +30,7 @@ export default async function RootMiddleware(
}
} else {
// rewrite to root page unless the user defines a site to redirect to
- return NextResponse.next();
+ return NextResponse.rewrite(new URL(`/_root/${domain}`, req.url));
}
}
}
diff --git a/middleware.ts b/middleware.ts
index 0752cd8646..e484c53034 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -17,13 +17,13 @@ export const config = {
/*
* Match all paths except for:
* 1. /api/ routes
- * 2. /_next (Next.js internals)
- * 3. /_proxy & /_auth (special pages for OG tag proxying and password protection)
+ * 2. /_next/ (Next.js internals)
+ * 3. /_proxy/, /_auth/, /_root/ (special pages for OG tags proxying, password protection, and placeholder _root pages)
* 4. /_static (inside /public)
* 5. /_vercel (Vercel internals)
* 6. all root files inside /public (e.g. /favicon.ico)
*/
- "/((?!api/|_next|_proxy|_auth|_static|_vercel|[\\w-]+\\.\\w+).*)",
+ "/((?!api/|_next/|_proxy/|_auth/|_root/|_static|_vercel|[\\w-]+\\.\\w+).*)",
],
};
diff --git a/pages/_root/[domain].tsx b/pages/_root/[domain].tsx
new file mode 100644
index 0000000000..c40a757899
--- /dev/null
+++ b/pages/_root/[domain].tsx
@@ -0,0 +1,111 @@
+import prisma from "@/lib/prisma";
+import Background from "@/components/shared/background";
+import Meta from "@/components/layout/meta";
+import { useState } from "react";
+import { motion } from "framer-motion";
+import { useDebounce } from "use-debounce";
+import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
+import Spline from "@splinetool/react-spline";
+import { InlineSnippet } from "@/components/app/settings/custom-domain/domain-configuration";
+
+export default function Placeholder({ domain }: { domain: string }) {
+ const [loading, setLoading] = useState(true);
+ const onLoad = () => {
+ setLoading(false);
+ };
+ // workarouond to avoid the blinking effect when Spline loads
+ const [opacity] = useDebounce(loading ? 0 : 1, 200);
+
+ const [showText] = useDebounce(loading ? false : true, 800);
+
+ return (
+ <div className="flex h-screen flex-col items-center">
+ <Meta
+ title={`${domain.toUpperCase()} - A Dub Custom Domain`}
+ description={`${domain.toUpperCase()} is a custom domain on Dub - an open-source link management tool for modern marketing teams to create, share, and track short links.`}
+ />
+ <Background />
+ <motion.div
+ className="z-10"
+ exit={{ opacity: 0, scale: 0.95 }}
+ transition={{ duration: 0.5, type: "spring" }}
+ >
+ <div
+ className={`${
+ loading ? "scale-[25%] blur-md" : "scale-100 blur-0"
+ } mt-[7vh] h-[50vh] w-screen object-cover transition-all duration-1000`}
+ >
+ <Spline
+ onLoad={onLoad}
+ style={{ opacity: opacity }}
+ scene="https://prod.spline.design/cJkq6hsiUPNRHeMf/scene.splinecode"
+ />
+ </div>
+ {showText && (
+ <motion.div
+ variants={{
+ show: {
+ transition: {
+ staggerChildren: 0.3,
+ },
+ },
+ }}
+ initial="hidden"
+ animate="show"
+ className="mx-5 flex flex-col items-center space-y-10 text-center sm:mx-auto"
+ >
+ <motion.h1
+ className="font-display text-4xl font-bold text-gray-800 transition-colors sm:text-5xl"
+ variants={STAGGER_CHILD_VARIANTS}
+ >
+ Welcome to Dub
+ </motion.h1>
+ <motion.p
+ className="max-w-xl text-gray-600 transition-colors sm:text-lg"
+ variants={STAGGER_CHILD_VARIANTS}
+ >
+ <InlineSnippet>{domain}</InlineSnippet> is a custom domain on Dub
+ - a link management tool for modern marketing teams to create,
+ share, and track short links.
+ </motion.p>
+ <motion.a
+ variants={STAGGER_CHILD_VARIANTS}
+ href={`https://dub.sh?utm_source=${domain}&utm_medium=referral&utm_campaign=custom-domain`}
+ className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black"
+ >
+ Create Your Free Branded Link
+ </motion.a>
+ </motion.div>
+ )}
+ </motion.div>
+ </div>
+ );
+}
+
+export const getStaticPaths = async () => {
+ const domains = await prisma.project.findMany({
+ where: {
+ domainVerified: true,
+ },
+ select: {
+ domain: true,
+ },
+ });
+ return {
+ paths: domains.map(({ domain }) => ({
+ params: {
+ domain,
+ },
+ })),
+ fallback: "blocking",
+ };
+};
+
+export const getStaticProps = async (context) => {
+ const { domain } = context.params;
+ return {
+ props: {
+ domain,
+ },
+ };
+};
diff --git a/pages/app/welcome.tsx b/pages/app/welcome.tsx
index ca3dabd0a6..69335912f8 100644
--- a/pages/app/welcome.tsx
+++ b/pages/app/welcome.tsx
@@ -2,16 +2,11 @@ import Background from "@/components/shared/background";
import Intro from "@/components/app/welcome/intro";
import Interim from "@/components/app/welcome/interim";
import { AnimatePresence } from "framer-motion";
-import { Suspense, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import { useAddProjectModal } from "@/components/app/modals/add-project-modal";
import { useAddEditLinkModal } from "@/components/app/modals/add-edit-link-modal";
import Meta from "@/components/layout/meta";
-const staggerChildVariants = {
- hidden: { opacity: 0, y: 20 },
- show: { opacity: 1, y: 0, transition: { duration: 0.4, type: "spring" } },
-};
-
export default function Welcome() {
const [state, setState] = useState("intro");
@@ -41,24 +36,10 @@ export default function Welcome() {
<Background />
<AddProjectModal />
<AddEditLinkModal />
- <Suspense>
- <AnimatePresence mode="wait">
- {state === "intro" && (
- <Intro
- key="intro"
- setState={setState}
- staggerChildVariants={staggerChildVariants}
- />
- )}
- {state === "interim" && (
- <Interim
- key="interim"
- setState={setState}
- staggerChildVariants={staggerChildVariants}
- />
- )}
- </AnimatePresence>
- </Suspense>
+ <AnimatePresence mode="wait">
+ {state === "intro" && <Intro key="intro" setState={setState} />}
+ {state === "interim" && <Interim key="interim" setState={setState} />}
+ </AnimatePresence>
</div>
);
}
diff --git a/pages/placeholder/[[...domain]].tsx b/pages/placeholder/[[...domain]].tsx
deleted file mode 100644
index 8e4f5189a5..0000000000
--- a/pages/placeholder/[[...domain]].tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import { GetStaticProps } from "next";
-import { ParsedUrlQuery } from "querystring";
-import HomeLayout from "@/components/layout/home";
-
-export default function Placeholder() {
- return <HomeLayout>hello</HomeLayout>;
-}
-interface Params extends ParsedUrlQuery {
- slug: string[];
-}
-
-export const getStaticPaths = async () => {
- return {
- paths: [],
- fallback: "blocking",
- };
-};
-
-export const getStaticProps: GetStaticProps = async (context) => {
- const { domain } = context.params as Params;
- return {
- props: {
- domain,
- },
- };
-};