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.

add noindex column

Kiran K72c7d8079b34
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index e3debf4992..baf3dceb64 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -61,9 +61,6 @@ export const PATCH = withWorkspace(
workspace,
});
- // TODO:
- // Store noindex
-
waitUntil(
Promise.all([
setRootDomain({
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index a3e4e817b1..7dbf05a5dc 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -26,6 +26,7 @@ export const GET = withWorkspace(async ({ workspace }) => {
rewrite: true,
clicks: true,
expiredUrl: true,
+ noindex: true,
},
take: 1,
},
@@ -82,9 +83,6 @@ export const POST = withWorkspace(async ({ req, workspace, session }) => {
userId: session.user.id,
});
- // TODO:
- // Store noindex
-
waitUntil(
setRootDomain({
id: domainRecord.id,
diff --git a/apps/web/lib/api/domains/add-domain.ts b/apps/web/lib/api/domains/add-domain.ts
index 01d3837ea8..84311bac15 100644
--- a/apps/web/lib/api/domains/add-domain.ts
+++ b/apps/web/lib/api/domains/add-domain.ts
@@ -21,7 +21,8 @@ export const addDomain = async (input: AddDomainInput) => {
target,
expiredUrl,
userId,
- archived = false,
+ noindex,
+ archived,
} = input;
// Add domain to the workspace
@@ -55,11 +56,13 @@ export const addDomain = async (input: AddDomainInput) => {
url: "",
expiredUrl: null,
rewrite: false,
+ noindex: false,
}
: {
url: target || "",
expiredUrl: expiredUrl || null,
rewrite: type === "rewrite",
+ noindex: noindex,
}),
},
workspace,
diff --git a/apps/web/lib/api/domains/get-domain.ts b/apps/web/lib/api/domains/get-domain.ts
index 43fdda640f..b0e2972ac4 100644
--- a/apps/web/lib/api/domains/get-domain.ts
+++ b/apps/web/lib/api/domains/get-domain.ts
@@ -25,6 +25,7 @@ export const getDomain = async (input: GetDomainInput) => {
rewrite: true,
clicks: true,
expiredUrl: true,
+ noindex: true,
},
take: 1,
},
diff --git a/apps/web/lib/api/domains/transform-domain.ts b/apps/web/lib/api/domains/transform-domain.ts
index eb4aef5076..bc642725e2 100644
--- a/apps/web/lib/api/domains/transform-domain.ts
+++ b/apps/web/lib/api/domains/transform-domain.ts
@@ -1,26 +1,27 @@
-import { DomainSchema } from "@/lib/zod/schemas/domains";
import { Domain, Link } from "@prisma/client";
type Input = Domain & {
- links: Pick<Link, "url" | "rewrite" | "clicks" | "expiredUrl">[];
+ links: Pick<Link, "url" | "rewrite" | "clicks" | "expiredUrl" | "noindex">[];
};
export const transformDomain = (domain: Input) => {
const { id, slug, verified, primary, archived, placeholder } = domain;
- const { url, rewrite, clicks, expiredUrl } = domain.links[0];
+ const { url, rewrite, clicks, expiredUrl, noindex } = domain.links[0];
- return DomainSchema.parse({
+ return {
id,
slug,
verified,
primary,
archived,
+ noindex,
placeholder,
expiredUrl,
target: url || null,
+ url: url || null, // Deprecated
type: rewrite ? "rewrite" : "redirect",
clicks,
createdAt: domain.createdAt,
updatedAt: domain.updatedAt,
- });
+ };
};
diff --git a/apps/web/lib/api/domains/update-domain.ts b/apps/web/lib/api/domains/update-domain.ts
index e4123b41bb..2ae27fe638 100644
--- a/apps/web/lib/api/domains/update-domain.ts
+++ b/apps/web/lib/api/domains/update-domain.ts
@@ -5,7 +5,6 @@ import { updateDomainBodySchema } from "@/lib/zod/schemas/domains";
import { DubApiError, ErrorCodes } from "../errors";
import { processLink, updateLink } from "../links";
import { getDomain } from "./get-domain";
-import { transformDomain } from "./transform-domain";
type UpdateDomainInput = z.infer<typeof updateDomainBodySchema> & {
newSlug?: string;
@@ -22,6 +21,7 @@ export const updateDomain = async (input: UpdateDomainInput) => {
target,
expiredUrl,
archived,
+ noindex,
} = input;
// Update domain
@@ -42,9 +42,14 @@ export const updateDomain = async (input: UpdateDomainInput) => {
});
// Skip link update if no link data is provided
- if (!("type" in input) && !("target" in input) && !("expiredUrl" in input)) {
- return transformDomain(domain);
- }
+ // if (
+ // !("type" in input) &&
+ // !("target" in input) &&
+ // !("expiredUrl" in input) &&
+ // !("noindex" in input)
+ // ) {
+ // return transformDomain(domain);
+ // }
const link = domain.links[0];
@@ -59,6 +64,7 @@ export const updateDomain = async (input: UpdateDomainInput) => {
...("rewrite" in input && { rewrite: type === "rewrite" }),
...("target" in input && { url: target || "" }),
...("expiredUrl" in input && { expiredUrl }),
+ ...("noindex" in input && { noindex }),
}),
};
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index d891a4a287..571ba15782 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -88,9 +88,11 @@ export const addDomainBodySchema = z.object({
noindex: z
.boolean()
.optional()
+ .default(false)
.describe(
"Prevent search engines from indexing the domain. Defaults to `false`.",
- ),
+ )
+ .openapi({ example: false }),
placeholder: parseUrlSchema
.nullish()
.default("https://dub.co/help/article/what-is-dub")
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 2edd524a53..a0ad4c76d1 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -236,6 +236,11 @@ export const createLinkBodySchema = z.object({
"Geo targeting information for the short link in JSON format `{[COUNTRY]: https://example.com }`.",
)
.openapi({ ref: "linkGeoTargeting" }),
+ noindex: z
+ .boolean()
+ .optional()
+ .default(false)
+ .describe("Whether to noindex the short link."),
});
export const updateLinkBodySchema = createLinkBodySchema.partial().optional();
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index b3172bd968..853a8115d2 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -223,6 +223,8 @@ model Link {
// Link cloaking/masking via rewrite
rewrite Boolean @default(false) // whether to rewrite the link or not
+
+ noindex Boolean @default(false) // whether to noindex the link or not
// Custom device targeting
ios String? @db.LongText // custom link for iOS devices
diff --git a/apps/web/tests/domains/index.test.ts b/apps/web/tests/domains/index.test.ts
index a60bebb630..2bc901c15a 100644
--- a/apps/web/tests/domains/index.test.ts
+++ b/apps/web/tests/domains/index.test.ts
@@ -24,8 +24,11 @@ const expectedDomain = {
placeholder: domainRecord.placeholder,
expiredUrl: domainRecord.expiredUrl,
target: domainRecord.target,
+ url: domainRecord.target,
type: domainRecord.type,
clicks: 0,
+ createdAt: expect.any(String),
+ updatedAt: expect.any(String),
};
describe.sequential("/domains/**", async () => {
@@ -123,7 +126,7 @@ describe.sequential("/domains/**", async () => {
expect(domain).toStrictEqual({
...expectedDomain,
...toUpdate,
- primary: true,
+ url: toUpdate.target,
});
});
});