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.

Revert /domains/** changes

Kiran Kb9739ec2f9ad
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 b95f2dbfe2..08d2c67b7c 100644
--- a/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts
+++ b/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts
@@ -7,43 +7,39 @@ import {
validateDomain,
} from "@/lib/api/domains";
import { withAuth } from "@/lib/auth";
-import { DubApiError, handleAndReturnErrorResponse } from "@/lib/errors";
import prisma from "@/lib/prisma";
import { DUB_PROJECT_ID, isDubDomain } from "@dub/utils";
import { NextResponse } from "next/server";
// GET /api/projects/[slug]/domains/[domain] – get a project's domain
export const GET = withAuth(async ({ domain, project }) => {
- try {
- if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {
- throw new DubApiError({
- code: "forbidden",
- message: "Domain does not belong to project.",
- });
- }
-
- const data = await prisma.domain.findUniqueOrThrow({
- where: {
- slug: domain,
- },
- select: {
- slug: true,
- verified: true,
- primary: true,
- target: true,
- type: true,
- placeholder: true,
- clicks: true,
- },
+ if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {
+ return new Response("Domain does not belong to project.", {
+ status: 403,
});
+ }
- return NextResponse.json({
- ...data,
- url: data.target,
- });
- } catch (error) {
- return handleAndReturnErrorResponse(error);
+ const data = await prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ },
+ select: {
+ slug: true,
+ verified: true,
+ primary: true,
+ target: true,
+ type: true,
+ placeholder: true,
+ clicks: true,
+ },
+ });
+ if (!data) {
+ return new Response("Domain not found", { status: 404 });
}
+ return NextResponse.json({
+ ...data,
+ url: data.target,
+ });
});
// PUT /api/projects/[slug]/domains/[domain] – edit a project's domain
@@ -136,17 +132,12 @@ export const PUT = withAuth(async ({ req, project, domain }) => {
// DELETE /api/projects/[slug]/domains/[domain] - delete a project's domain
export const DELETE = withAuth(async ({ domain, project }) => {
- try {
- if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {
- throw new DubApiError({
- code: "forbidden",
- message: "Domain does not belong to project.",
- });
- }
-
- const response = await deleteDomainAndLinks(domain);
- return NextResponse.json(response);
- } catch (error) {
- return handleAndReturnErrorResponse(error);
+ if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {
+ return new Response("Domain does not belong to project.", {
+ status: 403,
+ });
}
-});
+
+ const response = await deleteDomainAndLinks(domain);
+ return NextResponse.json(response);
+});
\ No newline at end of file
diff --git a/apps/web/app/api/projects/[slug]/domains/route.ts b/apps/web/app/api/projects/[slug]/domains/route.ts
index 1c786cda94..109664004a 100644
--- a/apps/web/app/api/projects/[slug]/domains/route.ts
+++ b/apps/web/app/api/projects/[slug]/domains/route.ts
@@ -6,17 +6,8 @@ import {
import { exceededLimitError } from "@/lib/api/errors";
import { withAuth } from "@/lib/auth";
import prisma from "@/lib/prisma";
-import z, { domainSchema } from "@/lib/zod";
import { NextResponse } from "next/server";
-const addDomainSchema = z.object({
- slug: domainSchema,
- primary: z.boolean().optional().default(false),
- archived: z.boolean().optional().default(false),
- target: z.string(),
- type: z.enum(["redirect", "rewrite"]),
-});
-
// GET /api/projects/[slug]/domains – get all domains for a project
export const GET = withAuth(async ({ project }) => {
const domains = await prisma.domain.findMany({
diff --git a/apps/web/lib/zod/index.ts b/apps/web/lib/zod/index.ts
index 56b1ebc400..32898654ae 100644
--- a/apps/web/lib/zod/index.ts
+++ b/apps/web/lib/zod/index.ts
@@ -1,4 +1,3 @@
-import { validDomainRegex } from "@dub/utils";
import * as z from "zod";
import { extendZodWithOpenApi } from "zod-openapi";
@@ -6,18 +5,6 @@ extendZodWithOpenApi(z);
export default z;
-export const domainSchema = z
- .string()
- .min(1)
- .refine((domain) => {
- const validDomain =
- validDomainRegex.test(domain) &&
- // make sure the domain doesn't contain dub.co/dub.sh
- !/^(dub\.co|.*\.dub\.co|dub\.sh|.*\.dub\.sh)$/i.test(domain);
-
- return validDomain;
- }, "Invalid domain");
-
export const domainKeySchema = z.object({
domain: z.string().min(1),
key: z.string().min(1),