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.

use parseUrlSchema

Kiran Ke2412ba938a7
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index 3e78b8319e..50cdc37ee9 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -99,7 +99,7 @@ export const PUT = withAuth(
id: response[0].id,
domain,
...(workspace.plan !== "free" && {
- url: target,
+ url: target || undefined,
}),
rewrite: type === "rewrite",
...(newDomain !== domain && {
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index df7f8f4694..bd3bc62e32 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -89,7 +89,7 @@ export const POST = withAuth(async ({ req, workspace }) => {
domain,
projectId: workspace.id,
...(workspace.plan !== "free" && {
- url: target,
+ url: target || undefined,
}),
rewrite: type === "rewrite",
});
diff --git a/apps/web/lib/openapi/metatags/index.ts b/apps/web/lib/openapi/metatags/index.ts
index bab1da443d..a62fc265d7 100644
--- a/apps/web/lib/openapi/metatags/index.ts
+++ b/apps/web/lib/openapi/metatags/index.ts
@@ -7,7 +7,7 @@ const getMetatags: ZodOpenApiOperationObject = {
summary: "Retrieve the metatags for a URL",
description: "Retrieve the metatags for a URL",
requestParams: {
- query: getUrlQuerySchema,
+ query: getUrlQuerySchema.describe("The URL to retrieve metatags for"),
},
responses: {
"200": {
@@ -30,7 +30,7 @@ const getMetatags: ZodOpenApiOperationObject = {
description: "The OpenGraph image for the URL",
},
},
- },
+ }, // TODO: use zod schema here
},
},
},
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index 78623f601a..fb4408e01b 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -48,27 +48,25 @@ export const DomainSchema = z.object({
export const addDomainBodySchema = z.object({
slug: z
- .string({ required_error: "Domain name is required" })
- .min(1, "Domain name cannot be empty.")
+ .string({ required_error: "slug is required" })
+ .min(1, "slug cannot be empty.")
.describe("Name of the domain."),
- target: parseUrlSchema
- .nullable()
- .describe(
- "The page your users will get redirected to when they visit your domain.",
- ),
type: z
.enum(["redirect", "rewrite"])
.optional()
.default("redirect")
.describe("The type of redirect to use for this domain."),
+ target: parseUrlSchema
+ .nullish()
+ .describe(
+ "The page your users will get redirected to when they visit your domain.",
+ ),
expiredUrl: parseUrlSchema
- .nullable()
+ .nullish()
.describe(
"Redirect users to a specific URL when any link under this domain has expired.",
),
- placeholder: z
- .string()
- .url("placeholder must be a valid URL")
+ placeholder: parseUrlSchema
.optional()
.default("https://dub.co/help/article/what-is-dub")
.describe(
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 0f86edb48c..243140b4b9 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -10,7 +10,6 @@ import { TagSchema } from "./tags";
export const parseUrlSchema = z
.string()
- .describe("The destination URL of the short link.")
.transform((v) => getUrlFromString(v))
.refine((v) => isValidUrl(v), { message: "Invalid URL" });