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.

final fixes

Steven Teya25878633c46
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 89b5e00d5e..654e3348e5 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -1,6 +1,6 @@
-import { validateAllowedHostnames } from "@/lib/api/allowed-hostnames";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
+import { validateAllowedHostnames } from "@/lib/api/validate-allowed-hostnames";
import { deleteWorkspace } from "@/lib/api/workspaces";
import { withWorkspace } from "@/lib/auth";
import { getFeatureFlags } from "@/lib/edge-config";
@@ -70,7 +70,7 @@ export const PATCH = withWorkspace(
}
const validHostnames = allowedHostnames
- ? await validateAllowedHostnames(allowedHostnames)
+ ? validateAllowedHostnames(allowedHostnames)
: undefined;
const logoUploaded = logo
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/allowed-hostnames.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/allowed-hostnames.tsx
index b81edc1ffb..ff82114ea6 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/allowed-hostnames.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/allowed-hostnames.tsx
@@ -51,7 +51,10 @@ const AddHostnameForm = () => {
return;
}
- if (!validDomainRegex.test(hostname)) {
+ const isHostnameValid =
+ validDomainRegex.test(hostname) || hostname === "localhost";
+
+ if (!isHostnameValid) {
toast.error("Enter a valid domain.");
return;
}
@@ -80,7 +83,8 @@ const AddHostnameForm = () => {
setHostname("");
};
- const isHostnameValid = validDomainRegex.test(hostname);
+ const isHostnameValid =
+ validDomainRegex.test(hostname) || hostname === "localhost";
return (
<form
diff --git a/apps/web/lib/api/allowed-hostnames.ts b/apps/web/lib/api/validate-allowed-hostnames.ts
similarity index 82%
rename from apps/web/lib/api/allowed-hostnames.ts
rename to apps/web/lib/api/validate-allowed-hostnames.ts
index a703dd02b2..9417d4e0f0 100644
--- a/apps/web/lib/api/allowed-hostnames.ts
+++ b/apps/web/lib/api/validate-allowed-hostnames.ts
@@ -3,7 +3,7 @@ import { DubApiError } from "./errors";
const MAX_HOSTNAMES_ALLOWED = 10;
-export const validateAllowedHostnames = async (
+export const validateAllowedHostnames = (
allowedHostnames: string[] | undefined,
) => {
if (!allowedHostnames) {
@@ -12,8 +12,8 @@ export const validateAllowedHostnames = async (
allowedHostnames = [...new Set(allowedHostnames)];
- const results = await Promise.all(
- allowedHostnames.map((hostname) => validDomainRegex.test(hostname)),
+ const results = allowedHostnames.map(
+ (hostname) => validDomainRegex.test(hostname) || hostname === "localhost",
);
const invalidHostnames = results.filter((result) => !result);