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.

added cloudflare domains docs, small bug fixes, cmdk analytics

Steven Teyf42e2d705580
diff --git a/app/ui/cmdk.tsx b/app/ui/cmdk.tsx
index 7c91b28e96..4edb3218f7 100644
--- a/app/ui/cmdk.tsx
+++ b/app/ui/cmdk.tsx
@@ -18,6 +18,8 @@ import { useRouter } from "next/navigation";
import Highlighter from "react-highlight-words";
import { APP_HOSTNAMES, HOME_DOMAIN } from "#/lib/constants";
import Fuse from "fuse.js";
+import { useDebouncedCallback } from "use-debounce";
+import va from "@vercel/analytics";
function CMDKHelper({
showCMDK,
@@ -27,6 +29,12 @@ function CMDKHelper({
setShowCMDK: Dispatch<SetStateAction<boolean>>;
}) {
const commandListRef = useRef<HTMLDivElement>(null);
+ const debouncedTrackSearch = useDebouncedCallback((query: string) => {
+ va.track("CMDK Search", {
+ query,
+ });
+ }, 1000);
+
return (
<Modal
showModal={showCMDK}
@@ -36,11 +44,12 @@ function CMDKHelper({
<Command label="CMDK" loop shouldFilter={false}>
<Command.Input
autoFocus
- onInput={() => {
+ onInput={(e) => {
// hack to scroll to top of list when input changes (for some reason beyond my comprehension, setTimeout is needed)
setTimeout(() => {
commandListRef.current?.scrollTo(0, 0);
}, 0);
+ debouncedTrackSearch(e.currentTarget.value);
}}
placeholder="Search articles, guides, and more..."
className="w-full border-none p-4 font-normal placeholder-gray-400 focus:outline-none focus:ring-0"
@@ -152,7 +161,8 @@ export default function useCMDK() {
// Toggle the menu when ⌘K is pressed
useEffect(() => {
const down = (e: KeyboardEvent) => {
- if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
+ const existingModalBackdrop = document.getElementById("modal-backdrop");
+ if (e.key === "k" && (e.metaKey || e.ctrlKey) && !existingModalBackdrop) {
e.preventDefault();
setShowCMDK((showCMDK) => !showCMDK);
}
diff --git a/app/ui/content/mdx.tsx b/app/ui/content/mdx.tsx
index 4a0740444c..9a4c4f3875 100644
--- a/app/ui/content/mdx.tsx
+++ b/app/ui/content/mdx.tsx
@@ -13,6 +13,7 @@ import "react-medium-image-zoom/dist/styles.css";
import { HELP_CATEGORIES, getPopularArticles } from "#/lib/constants/content";
import ArticleLink from "./article-link";
import CategoryCard from "./category-card";
+import { ListChecks } from "lucide-react";
const CustomLink = (props: any) => {
const href = props.href;
@@ -60,6 +61,15 @@ const components = {
{...props}
/>
),
+ Prerequisites: (props: any) => (
+ <div className="mt-4 rounded-md border border-gray-200 bg-white px-6 py-1 text-[0.95rem] leading-[1.4rem] shadow-md">
+ <div className="-mb-6 flex items-center space-x-2 text-gray-600">
+ <ListChecks size={20} />
+ <p className="text-sm font-medium uppercase">Prerequisites</p>
+ </div>
+ {props.children}
+ </div>
+ ),
PopularArticles: () => (
<div className="not-prose grid gap-2 rounded-xl border border-gray-200 bg-white p-4">
{getPopularArticles().map((article) => (
diff --git a/components/app/modals/add-edit-link-modal/tags-section.tsx b/components/app/modals/add-edit-link-modal/tags-section.tsx
index fe732211c3..c95f5f87f5 100644
--- a/components/app/modals/add-edit-link-modal/tags-section.tsx
+++ b/components/app/modals/add-edit-link-modal/tags-section.tsx
@@ -161,11 +161,12 @@ export default function TagsSection({
<Command.Empty>
{inputValue.length > 0 && (
<button
+ type="button"
onClick={() => createTag(inputValue)}
className="flex w-full cursor-pointer items-center rounded-md bg-gray-100 px-4 py-2 text-sm text-gray-900 hover:text-gray-900 aria-selected:bg-gray-100 aria-selected:text-gray-900"
>
Create tag{" "}
- <span className="ml-1.5 rounded-md bg-blue-100 px-2 py-0.5 text-blue-600">
+ <span className="ml-1.5 rounded-md bg-gray-200 px-2 py-0.5 text-gray-800">
{inputValue}
</span>
</button>
diff --git a/components/app/modals/import-short-modal.tsx b/components/app/modals/import-short-modal.tsx
index ec2ffbdada..d6d16e2e58 100644
--- a/components/app/modals/import-short-modal.tsx
+++ b/components/app/modals/import-short-modal.tsx
@@ -138,38 +138,36 @@ function ImportShortModal({
}}
className="flex flex-col space-y-4"
>
- <div className="divide-y divide-gray-200">
+ <div className="flex flex-col space-y-2">
+ <p className="text-sm font-medium text-gray-700">Domains</p>
{domains.map(({ id, domain, links }) => (
- <div key={id} className="flex flex-col space-y-2">
- <p className="text-sm font-medium text-gray-700">Domains</p>
- <div className="flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white px-4 py-2">
- <div>
- <p className="font-medium text-gray-800">{domain}</p>
- <p className="text-xs text-gray-500">
- {nFormatter(links)} links found
- </p>
- </div>
- <Switch
- fn={() => {
- const selected = isSelected(domain);
- if (selected) {
- setSelectedDomains((prev) =>
- prev.filter((d) => d.domain !== domain),
- );
- } else {
- setSelectedDomains((prev) => [
- ...prev,
- {
- id,
- domain,
- links,
- },
- ]);
- }
- }}
- checked={isSelected(domain)}
- />
+ <div className="flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white px-4 py-2">
+ <div>
+ <p className="font-medium text-gray-800">{domain}</p>
+ <p className="text-xs text-gray-500">
+ {nFormatter(links)} links found
+ </p>
</div>
+ <Switch
+ fn={() => {
+ const selected = isSelected(domain);
+ if (selected) {
+ setSelectedDomains((prev) =>
+ prev.filter((d) => d.domain !== domain),
+ );
+ } else {
+ setSelectedDomains((prev) => [
+ ...prev,
+ {
+ id,
+ domain,
+ links,
+ },
+ ]);
+ }
+ }}
+ checked={isSelected(domain)}
+ />
</div>
))}
</div>
diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsx
index c821374276..711feb528b 100644
--- a/components/layout/app/index.tsx
+++ b/components/layout/app/index.tsx
@@ -105,7 +105,9 @@ export default function AppLayout({
<Divider className="h-8 w-8 text-gray-200 sm:mr-3" />
<Link
href={
- slug ? `/${slug}/${domain}/${key}` : `/links/${key}`
+ slug
+ ? `/${slug}/${domain}/${encodeURIComponent(key)}`
+ : `/links/${encodeURIComponent(key)}`
}
className="text-sm font-medium"
>
diff --git a/content/help/how-to-add-custom-domain.mdx b/content/help/how-to-add-custom-domain.mdx
index 307f96d148..ca12282c21 100644
--- a/content/help/how-to-add-custom-domain.mdx
+++ b/content/help/how-to-add-custom-domain.mdx
@@ -7,15 +7,16 @@ categories:
- custom-domains
- getting-started
related:
- - what-is-a-project
- how-to-redirect-root-domain
+ - using-cloudflare-domains
+ - what-is-a-project
---
Dub is the only link management tool that allows you to add a custom domain for free. On Dub, you can add as many domains as you want on all plans – including the free plan.
This guide will show you how to add a custom domain to Dub.
-## Prerequisites
+<Prerequisites>
Before you begin, you'll need the following:
@@ -26,6 +27,8 @@ Before you begin, you'll need the following:
- [Google Domains](https://domains.google/)
- [Porkbun](https://porkbun.com/)
+</Prerequisites>
+
## Step 1: Add a custom domain
First, [log in](https://app.dub.sh/login) to your Dub account.
@@ -84,6 +87,12 @@ If you're adding a subdomain (e.g. `go.example.com`), you'll need to add a `CNAM
- **Value**: `cname.dub.sh`
- **TTL**: `86400` (or the highest value possible)
+<Note variant="warning">
+ If you're using Cloudflare as your DNS provider, you might need to configure
+ some extra steps for it to work properly. Please refer to our guide on [using
+ Cloudflare domains with Dub](using-cloudflare-domains) for more information.
+</Note>
+
## Step 3 (optional): Verify domain ownership
<Note variant="info">
diff --git a/content/help/using-cloudflare-domains.mdx b/content/help/using-cloudflare-domains.mdx
new file mode 100644
index 0000000000..2886af9db3
--- /dev/null
+++ b/content/help/using-cloudflare-domains.mdx
@@ -0,0 +1,50 @@
+---
+title: Using Cloudflare domains with Dub
+updatedAt: 2023-08-03
+summary: Learn how to use Cloudflare domains for your Dub project
+author: steventey
+categories:
+ - custom-domains
+related:
+ - how-to-add-custom-domain
+ - how-to-redirect-root-domain
+---
+
+If you're using a domain on Cloudflare for your Dub project, you might need to configure a few extra steps to make sure that your domain works properly.
+
+<Prerequisites>
+ If you haven't already, you'll need to add your domain to your Dub project.
+ You can learn how to do that [here](how-to-add-custom-domain).
+</Prerequisites>
+
+## Using Cloudflare's Proxy
+
+If 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.
+
+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.
+3. Under **Overview**, select the **Full** option.
+
+<Image
+ alt={`SSL/TLS encryption mode needs to be set to "Full" on Cloudflare`}
+ src="https://d2vwwcvoksz7ty.cloudfront.net/help/cloudflare-domain-full.png"
+ width={1822}
+ height={1088}
+/>
+
+This will make sure that the traffic to your domain is always encrypted between Cloudflare and Dub. You can learn more about Cloudflare's SSL/TLS encryption modes [here](https://developers.cloudflare.com/ssl/origin-configuration/ssl-modes/).
+
+## Using Cloudflare's DNS only (without proxy)
+
+If you're only using Cloudflare's DNS for your custom domain, all you need to do is [set your domain's DNS records](how-to-add-custom-domain#step-2-configure-your-domain) to point to Dub's servers and make sure that you're using the **DNS only** option on Cloudflare.
+
+<Image
+ alt={`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}
+/>
+
+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/links.ts b/lib/api/links.ts
index a41ca59a75..729b6b9e5b 100644
--- a/lib/api/links.ts
+++ b/lib/api/links.ts
@@ -34,13 +34,15 @@ export async function getLinksForProject({
...(domain && { domain }),
...(search && {
OR: [
- // if search query is 4 characters or shorter, only search for exact matches, else use MySQL fullTextSearch
+ // Use MySQL fullTextSearch for search queries longer than 4 characters, else use exact matches
{
- key: search.length <= 4 ? { contains: search } : { search },
- },
- {
- url: search.length <= 4 ? { contains: search } : { search },
+ key: search.length > 4 ? { search } : { contains: search },
},
+ search.length > 4
+ ? {
+ url: { search },
+ }
+ : {},
],
}),
...(tagId && { tagId }),
@@ -79,13 +81,15 @@ export async function getLinksCount({
...(userId && { userId }),
...(search && {
OR: [
- // if search query is 4 characters or shorter, only search for exact matches, else use MySQL fullTextSearch
- {
- key: search.length <= 4 ? { contains: search } : { search },
- },
+ // Use MySQL fullTextSearch for search queries longer than 4 characters, else use exact matches
{
- url: search.length <= 4 ? { contains: search } : { search },
+ key: search.length > 4 ? { search } : { contains: search },
},
+ search.length > 4
+ ? {
+ url: { search },
+ }
+ : {},
],
}),
// when filtering by domain, only filter by domain if the filter group is not "Domains"
diff --git a/pages/api/projects/[slug]/tags/index.ts b/pages/api/projects/[slug]/tags/index.ts
index 612605c93f..5a2526fe22 100644
--- a/pages/api/projects/[slug]/tags/index.ts
+++ b/pages/api/projects/[slug]/tags/index.ts
@@ -15,7 +15,7 @@ export default withProjectAuth(async (req, res, project) => {
color: true,
},
orderBy: {
- createdAt: "desc",
+ name: "asc",
},
});
return res.status(200).json(tags);