The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add misc/ endpoints
Steven Teyb89c954f0b73
diff --git a/apps/web/app/api/misc/check-favicon/route.ts b/apps/web/app/api/misc/check-favicon/route.tsnew file mode 100644index 0000000000..4084cd1ff5--- /dev/null+++ b/apps/web/app/api/misc/check-favicon/route.ts@@ -0,0 +1,40 @@+import { withSession } from "@/lib/auth";+import { GOOGLE_FAVICON_URL } from "@dub/utils";+import { NextResponse } from "next/server";++export const GET = withSession(async ({ searchParams }) => {+ const { domain } = searchParams;++ if (!domain) {+ return NextResponse.json(+ { error: "Domain parameter is required" },+ { status: 400 },+ );+ }++ try {+ const faviconUrl = `${GOOGLE_FAVICON_URL}${domain}`;++ const response = await fetch(faviconUrl, {+ method: "HEAD",+ headers: {+ "User-Agent": "Mozilla/5.0 (compatible; Dub/1.0)",+ },+ });++ return NextResponse.json({+ exists: response.ok,+ status: response.status,+ url: faviconUrl,+ });+ } catch (error) {+ console.error("Error checking favicon:", error);+ return NextResponse.json(+ {+ exists: false,+ error: "Failed to check favicon",+ },+ { status: 500 },+ );+ }+});diff --git a/apps/web/app/api/workspaces/[idOrSlug]/exists/route.ts b/apps/web/app/api/misc/check-workspace-slug/route.tssimilarity index 74%rename from apps/web/app/api/workspaces/[idOrSlug]/exists/route.tsrename to apps/web/app/api/misc/check-workspace-slug/route.tsindex 1c98b8d5b9..6f99e81377 100644--- a/apps/web/app/api/workspaces/[idOrSlug]/exists/route.ts+++ b/apps/web/app/api/misc/check-workspace-slug/route.ts@@ -3,9 +3,9 @@ import { prisma } from "@dub/prisma";import { DEFAULT_REDIRECTS, RESERVED_SLUGS } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/workspaces/[idOrSlug]/exists – check if a project exists-export const GET = withSession(async ({ params }) => {- const { idOrSlug: slug } = params;+// GET /api/misc/check-workspace-slug – check if a workspace slug is available+export const GET = withSession(async ({ searchParams }) => {+ const { slug } = searchParams;if (RESERVED_SLUGS.includes(slug) || DEFAULT_REDIRECTS[slug]) {return NextResponse.json(1);}diff --git a/apps/web/ui/workspaces/create-workspace-form.tsx b/apps/web/ui/workspaces/create-workspace-form.tsxindex a686c333fd..2a1d525bc3 100644--- a/apps/web/ui/workspaces/create-workspace-form.tsx+++ b/apps/web/ui/workspaces/create-workspace-form.tsx@@ -3,7 +3,7 @@import { isGenericEmail } from "@/lib/emails";import { AlertCircleFill } from "@/ui/shared/icons";import { Button, buttonVariants, FileUpload, useMediaQuery } from "@dub/ui";-import { cn, GOOGLE_FAVICON_URL } from "@dub/utils";+import { cn } from "@dub/utils";import slugify from "@sindresorhus/slugify";import { useSession } from "next-auth/react";import { usePlausible } from "next-plausible";@@ -45,7 +45,23 @@ export function CreateWorkspaceForm({useEffect(() => {if (session?.user?.email && !isGenericEmail(session.user.email)) {const emailDomain = session.user.email.split("@")[1];- setValue("logo", `${GOOGLE_FAVICON_URL}${emailDomain}`);++ // Check if favicon exists using our API endpoint+ fetch(`/api/misc/check-favicon?domain=${emailDomain}`)+ .then((response) => response.json())+ .then((data) => {+ if (data.exists) {+ console.log("Logo URL is valid:", data.url);+ setValue("logo", data.url);+ } else {+ // Don't set the logo if it returns an error+ console.log("Logo URL returned error:", data.status, data.url);+ }+ })+ .catch((error) => {+ // Don't set the logo if fetch fails+ console.log("Failed to check favicon:", error);+ });} else if (session?.user?.image) {setValue("logo", session.user.image);}@@ -147,16 +163,18 @@ export function CreateWorkspaceForm({pattern: /^[a-zA-Z0-9\-]+$/,})}onBlur={() => {- fetch(`/api/workspaces/${slug}/exists`).then(async (res) => {- if (res.status === 200) {- const exists = await res.json();- if (exists === 1)- setError("slug", {- message: `The slug "${slug}" is already in use.`,- });- else clearErrors("slug");- }- });+ fetch(`/api/misc/check-workspace-slug?slug=${slug}`).then(+ async (res) => {+ if (res.status === 200) {+ const exists = await res.json();+ if (exists === 1)+ setError("slug", {+ message: `The slug "${slug}" is already in use.`,+ });+ else clearErrors("slug");+ }+ },+ );}}aria-invalid="true"/>