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.

fix metatags api

Steven Teyf42b9a957c0b
diff --git a/apps/web/app/api/metatags/route.ts b/apps/web/app/api/links/metatags/route.ts
similarity index 57%
rename from apps/web/app/api/metatags/route.ts
rename to apps/web/app/api/links/metatags/route.ts
index 683349fd63..82dac1016e 100644
--- a/apps/web/app/api/metatags/route.ts
+++ b/apps/web/app/api/links/metatags/route.ts
@@ -6,37 +6,41 @@ import { getMetaTags } from "./utils";
export const runtime = "edge";
-const CORS_HEADERS = {
- "Access-Control-Allow-Origin": "*",
- "Access-Control-Allow-Methods": "GET, OPTIONS",
-};
-
export async function GET(req: NextRequest) {
try {
+ const origin = req.headers.get("origin");
+ // Validate the origin header and set CORS headers accordingly
+ const corsHeaders = {
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
+ "Access-Control-Allow-Headers": "Content-Type",
+ };
+
+ if (origin && origin.endsWith(".dub.co")) {
+ corsHeaders["Access-Control-Allow-Origin"] = origin;
+ }
+
+ // Validate URL parameter
const { url } = getUrlQuerySchema.parse({
url: req.nextUrl.searchParams.get("url"),
});
+ // Rate limit by IP
await ratelimitOrThrow(req, "metatags");
+ // Get metatags
const metatags = await getMetaTags(url);
+
+ // Return response
return NextResponse.json(
{
...metatags,
poweredBy: "Dub.co - Link management for modern marketing teams",
},
{
- headers: CORS_HEADERS,
+ headers: corsHeaders,
},
);
} catch (error) {
- return handleAndReturnErrorResponse(error, CORS_HEADERS);
+ return handleAndReturnErrorResponse(error);
}
}
-
-export function OPTIONS() {
- return new Response(null, {
- status: 204,
- headers: CORS_HEADERS,
- });
-}
diff --git a/apps/web/app/api/links/metatags/utils.ts b/apps/web/app/api/links/metatags/utils.ts
new file mode 100644
index 0000000000..32d12057d4
--- /dev/null
+++ b/apps/web/app/api/links/metatags/utils.ts
@@ -0,0 +1,168 @@
+import { recordMetatags } from "@/lib/upstash";
+import { fetchWithTimeout, isValidUrl } from "@dub/utils";
+import { waitUntil } from "@vercel/functions";
+import he from "he";
+import { parse } from "node-html-parser";
+
+export const getHtml = async (url: string) => {
+ const parsedUrl = new URL(url);
+ try {
+ const response = await fetchWithTimeout(url, {
+ headers: {
+ "User-Agent":
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Version H1cbA69",
+ Accept:
+ "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
+ "Accept-Language": "en-US,en;q=0.5",
+ "Accept-Encoding": "gzip, deflate, br",
+ Connection: "keep-alive",
+ "Upgrade-Insecure-Requests": "1",
+ "Sec-Fetch-Dest": "document",
+ "Sec-Fetch-Mode": "navigate",
+ "Sec-Fetch-Site": "none",
+ "Sec-Fetch-User": "?1",
+ "Cache-Control": "max-age=0",
+ Referer: `${parsedUrl.protocol}//${parsedUrl.hostname}`,
+ },
+ });
+
+ if (!response.ok) {
+ // If we get a 406 or other error, check if it's a Cloudflare-protected site
+ const isCloudflare = response.headers.get("server") === "cloudflare";
+ if (isCloudflare) {
+ console.warn(`Cloudflare-protected site detected: ${url}`);
+ return null;
+ }
+ console.error(`HTTP error! status: ${response.status} for URL: ${url}`);
+ return null;
+ }
+
+ const text = await response.text();
+
+ // Check if the response contains Cloudflare's challenge page
+ if (
+ text.includes("challenge-platform") ||
+ text.includes("cf-browser-verification")
+ ) {
+ console.warn(`Cloudflare challenge page detected for: ${url}`);
+ return null;
+ }
+
+ return text;
+ } catch (error) {
+ console.error(`Error fetching ${url}:`, error);
+ return null;
+ }
+};
+
+export const getHeadChildNodes = (html) => {
+ const ast = parse(html); // parse the html into AST format with node-html-parser
+ const metaTags = ast.querySelectorAll("meta").map(({ attributes }) => {
+ const property = attributes.property || attributes.name || attributes.href;
+ return {
+ property,
+ content: attributes.content,
+ };
+ });
+ const title = ast.querySelector("title")?.innerText;
+ const linkTags = ast.querySelectorAll("link").map(({ attributes }) => {
+ const { rel, href } = attributes;
+ return {
+ rel,
+ href,
+ };
+ });
+
+ return { metaTags, title, linkTags };
+};
+
+export const getRelativeUrl = (url: string, imageUrl: string) => {
+ if (!imageUrl) {
+ return null;
+ }
+ if (isValidUrl(imageUrl)) {
+ return imageUrl;
+ }
+ const { protocol, host } = new URL(url);
+ const baseURL = `${protocol}//${host}`;
+ return new URL(imageUrl, baseURL).toString();
+};
+
+const generateFallbackMetadata = (url: string) => {
+ try {
+ const parsedUrl = new URL(url);
+ const hostname = parsedUrl.hostname;
+ const path = parsedUrl.pathname;
+
+ // Clean up the path for title
+ const pathParts = path.split("/").filter(Boolean);
+ const lastPathPart = pathParts[pathParts.length - 1] || "";
+ const formattedPath = lastPathPart
+ .split("-")
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join(" ");
+
+ return {
+ title: formattedPath || hostname.replace(/^www\./, ""),
+ description: `Visit ${hostname}${path}`,
+ image: null,
+ };
+ } catch (e) {
+ return {
+ title: url,
+ description: "No description available",
+ image: null,
+ };
+ }
+};
+
+export const getMetaTags = async (url: string) => {
+ const html = await getHtml(url);
+ if (!html) {
+ // If we couldn't fetch the HTML (e.g., due to Cloudflare protection),
+ // generate fallback metadata from the URL
+ return generateFallbackMetadata(url);
+ }
+
+ const { metaTags, title: titleTag, linkTags } = getHeadChildNodes(html);
+
+ let object = {};
+
+ for (let k in metaTags) {
+ let { property, content } = metaTags[k];
+
+ // !object[property] → (meaning we're taking the first instance of a metatag and ignoring the rest)
+ property &&
+ !object[property] &&
+ (object[property] = content && he.decode(content));
+ }
+
+ for (let m in linkTags) {
+ let { rel, href } = linkTags[m];
+
+ // !object[rel] → (ditto the above)
+ rel && !object[rel] && (object[rel] = href);
+ }
+
+ const title = object["og:title"] || object["twitter:title"] || titleTag;
+
+ const description =
+ object["description"] ||
+ object["og:description"] ||
+ object["twitter:description"];
+
+ const image =
+ object["og:image"] ||
+ object["twitter:image"] ||
+ object["image_src"] ||
+ object["icon"] ||
+ object["shortcut icon"];
+
+ waitUntil(recordMetatags(url, title && description && image ? false : true));
+
+ return {
+ title: title || url,
+ description: description || "No description",
+ image: getRelativeUrl(url, image),
+ };
+};
diff --git a/apps/web/app/api/metatags/utils.ts b/apps/web/app/api/metatags/utils.ts
deleted file mode 100644
index 5be950ebb2..0000000000
--- a/apps/web/app/api/metatags/utils.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-import { recordMetatags } from "@/lib/upstash";
-import { fetchWithTimeout, isValidUrl } from "@dub/utils";
-import { waitUntil } from "@vercel/functions";
-import he from "he";
-import { parse } from "node-html-parser";
-
-export const getHtml = async (url: string) => {
- return await fetchWithTimeout(url, {
- headers: {
- "User-Agent": "Dub.co Metatags API (https://api.dub.co/metatags)",
- },
- })
- .then((r) => r.text())
- .catch(() => null);
-};
-
-export const getHeadChildNodes = (html) => {
- const ast = parse(html); // parse the html into AST format with node-html-parser
- const metaTags = ast.querySelectorAll("meta").map(({ attributes }) => {
- const property = attributes.property || attributes.name || attributes.href;
- return {
- property,
- content: attributes.content,
- };
- });
- const title = ast.querySelector("title")?.innerText;
- const linkTags = ast.querySelectorAll("link").map(({ attributes }) => {
- const { rel, href } = attributes;
- return {
- rel,
- href,
- };
- });
-
- return { metaTags, title, linkTags };
-};
-
-export const getRelativeUrl = (url: string, imageUrl: string) => {
- if (!imageUrl) {
- return null;
- }
- if (isValidUrl(imageUrl)) {
- return imageUrl;
- }
- const { protocol, host } = new URL(url);
- const baseURL = `${protocol}//${host}`;
- return new URL(imageUrl, baseURL).toString();
-};
-
-export const getMetaTags = async (url: string) => {
- const html = await getHtml(url);
- if (!html) {
- return {
- title: url,
- description: "No description",
- image: null,
- };
- }
- const { metaTags, title: titleTag, linkTags } = getHeadChildNodes(html);
-
- let object = {};
-
- for (let k in metaTags) {
- let { property, content } = metaTags[k];
-
- // !object[property] → (meaning we're taking the first instance of a metatag and ignoring the rest)
- property &&
- !object[property] &&
- (object[property] = content && he.decode(content));
- }
-
- for (let m in linkTags) {
- let { rel, href } = linkTags[m];
-
- // !object[rel] → (ditto the above)
- rel && !object[rel] && (object[rel] = href);
- }
-
- const title = object["og:title"] || object["twitter:title"] || titleTag;
-
- const description =
- object["description"] ||
- object["og:description"] ||
- object["twitter:description"];
-
- const image =
- object["og:image"] ||
- object["twitter:image"] ||
- object["image_src"] ||
- object["icon"] ||
- object["shortcut icon"];
-
- waitUntil(recordMetatags(url, title && description && image ? false : true));
-
- return {
- title: title || url,
- description: description || "No description",
- image: getRelativeUrl(url, image),
- };
-};
diff --git a/apps/web/app/app.dub.co/(auth)/oauth/authorize/page.tsx b/apps/web/app/app.dub.co/(auth)/oauth/authorize/page.tsx
index 2bb27e8ef4..976337af7b 100644
--- a/apps/web/app/app.dub.co/(auth)/oauth/authorize/page.tsx
+++ b/apps/web/app/app.dub.co/(auth)/oauth/authorize/page.tsx
@@ -5,7 +5,7 @@ import { authorizeRequestSchema } from "@/lib/zod/schemas/oauth";
import EmptyState from "@/ui/shared/empty-state";
import { BlurImage, Logo } from "@dub/ui";
import { CircleWarning, CubeSettings } from "@dub/ui/icons";
-import { HOME_DOMAIN, constructMetadata } from "@dub/utils";
+import { constructMetadata } from "@dub/utils";
import { ArrowLeftRight } from "lucide-react";
import { redirect } from "next/navigation";
import { Suspense } from "react";
@@ -62,7 +62,7 @@ export default async function Authorize({
)}
</a>
<ArrowLeftRight className="size-5 text-neutral-500" />
- <a href={HOME_DOMAIN} target="_blank" rel="noreferrer">
+ <a href="https://dub.co" target="_blank" rel="noreferrer">
<Logo className="size-12" />
</a>
</div>
diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
index ecc1821b78..70b05c1f01 100644
--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/link/form.tsx
@@ -73,7 +73,7 @@ export function Form() {
// If url is valid, continue to generate metatags, else return null
new URL(debouncedUrl);
setLoadingPreviewImage(true);
- const res = await fetch(`/api/metatags?url=${debouncedUrl}`);
+ const res = await fetch(`/api/links/metatags?url=${debouncedUrl}`);
if (res.ok) {
const results = await res.json();
setPreviewImage(results.image);
diff --git a/apps/web/app/cloaked/[url]/page.tsx b/apps/web/app/cloaked/[url]/page.tsx
index f110a6ffb1..e2f3cf30fc 100644
--- a/apps/web/app/cloaked/[url]/page.tsx
+++ b/apps/web/app/cloaked/[url]/page.tsx
@@ -3,7 +3,7 @@ import {
constructMetadata,
getApexDomain,
} from "@dub/utils";
-import { getMetaTags } from "app/api/metatags/utils";
+import { getMetaTags } from "app/api/links/metatags/utils";
export const runtime = "edge";
export const fetchCache = "force-no-store";
diff --git a/apps/web/lib/middleware/api.ts b/apps/web/lib/middleware/api.ts
index 0988aaddfd..c129bf9089 100644
--- a/apps/web/lib/middleware/api.ts
+++ b/apps/web/lib/middleware/api.ts
@@ -1,18 +1,14 @@
import { parse } from "@/lib/middleware/utils";
-import { HOME_DOMAIN } from "@dub/utils";
import { NextRequest, NextResponse } from "next/server";
export default function ApiMiddleware(req: NextRequest) {
- const { path, fullPath } = parse(req);
+ const { fullPath } = parse(req);
- // special case for /metatags
- if (path === "/metatags") {
- const url = req.nextUrl.searchParams.get("url");
- if (!url) {
- return NextResponse.redirect(`${HOME_DOMAIN}/tools/metatags`, {
- status: 301,
- });
- }
+ // redirect to dub.co for /metatags
+ if (fullPath.startsWith("/metatags")) {
+ return NextResponse.redirect("https://dub.co", {
+ status: 301,
+ });
}
// Note: we don't have to account for paths starting with `/api`
// since they're automatically excluded via our middleware matcher
diff --git a/apps/web/lib/middleware/utils/bots-list.ts b/apps/web/lib/middleware/utils/bots-list.ts
index 9a2d23140d..d1c5d498de 100644
--- a/apps/web/lib/middleware/utils/bots-list.ts
+++ b/apps/web/lib/middleware/utils/bots-list.ts
@@ -1,7 +1,6 @@
export const UA_BOTS = [
"bot", // most bots
"crawler", // most crawlers
- "metatags", // Dub.co Metatags API (https://api.dub.co/metatags)
"chatgpt", // ChatGPT
"bluesky", // Bluesky crawler
"facebookexternalhit", // Facebook crawler
@@ -18,6 +17,7 @@ export const UA_BOTS = [
"MetaInspector", // metatags.io
"Go-http-client", // Go-http-client/1.1 is a bot: https://user-agents.net/string/go-http-client-1-1
"iframely", // https://iframely.com/docs/about (used by Notion, Linear)
+ "H1cbA69", // internal links/metatags API
// new
"ia_archiver",
diff --git a/apps/web/lib/openapi/index.ts b/apps/web/lib/openapi/index.ts
index d01bfb5633..ac1015e2d0 100644
--- a/apps/web/lib/openapi/index.ts
+++ b/apps/web/lib/openapi/index.ts
@@ -13,7 +13,6 @@ import { embedTokensPaths } from "./embed-tokens";
import { eventsPath } from "./events";
import { foldersPaths } from "./folders";
import { linksPaths } from "./links";
-import { metatagsPath } from "./metatags";
import { partnersPaths } from "./partners";
import { qrCodePaths } from "./qr";
import { tagsPaths } from "./tags";
@@ -56,7 +55,6 @@ export const document = createDocument({
...workspacesPaths,
...embedTokensPaths,
...qrCodePaths,
- ...metatagsPath,
},
components: {
schemas: {
diff --git a/apps/web/lib/openapi/metatags/index.ts b/apps/web/lib/openapi/metatags/index.ts
deleted file mode 100644
index b50d592034..0000000000
--- a/apps/web/lib/openapi/metatags/index.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import z from "@/lib/zod";
-import { getUrlQuerySchema } from "@/lib/zod/schemas/links";
-import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
-import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
-
-const getMetatags: ZodOpenApiOperationObject = {
- operationId: "getMetatags",
- "x-speakeasy-name-override": "get",
- summary: "Retrieve the metatags for a URL",
- description: "Retrieve the metatags for a URL.",
- requestParams: {
- query: getUrlQuerySchema.merge(
- z.object({
- url: z.string().openapi({
- example: "https://dub.co",
- description: "The URL to retrieve metatags for.",
- }),
- }),
- ),
- },
- responses: {
- "200": {
- description: "The retrieved metatags",
- content: {
- "application/json": {
- schema: metaTagsSchema,
- },
- },
- },
- },
- tags: ["Metatags"],
-};
-
-export const metatagsPath: ZodOpenApiPathsObject = {
- "/metatags": {
- get: getMetatags,
- },
-};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 2998c89997..d2953ea8ec 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -1,5 +1,4 @@
import z from "@/lib/zod";
-import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
import {
PartnerEarningsSchema,
PartnerProfileCustomerSchema,
@@ -278,8 +277,6 @@ export const tagColors = [
export type DashboardProps = z.infer<typeof dashboardSchema>;
-export type MetaTag = z.infer<typeof metaTagsSchema>;
-
export type TokenProps = z.infer<typeof tokenSchema>;
export type OAuthAppProps = z.infer<typeof oAuthAppSchema>;
diff --git a/apps/web/lib/upstash/record-metatags.ts b/apps/web/lib/upstash/record-metatags.ts
index 3a2d311f52..ef546c03a6 100644
--- a/apps/web/lib/upstash/record-metatags.ts
+++ b/apps/web/lib/upstash/record-metatags.ts
@@ -2,7 +2,7 @@ import { getDomainWithoutWWW } from "@dub/utils";
import { redis } from "./redis";
/**
- * Recording metatags that were generated via `/api/metatags`
+ * Recording metatags that were generated via "/api/links/metatags"
* If there's an error, it will be logged to a separate redis list for debugging
**/
export async function recordMetatags(url: string, error: boolean) {
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index e8adadf927..bb749573a3 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -538,19 +538,19 @@ export const LinkSchema = z
.string()
.nullable()
.describe(
- "The title of the short link generated via `api.dub.co/metatags`. Will be used for Custom Social Media Cards if `proxy` is true.",
+ "The title of the short link. Will be used for Custom Social Media Cards if `proxy` is true.",
),
description: z
.string()
.nullable()
.describe(
- "The description of the short link generated via `api.dub.co/metatags`. Will be used for Custom Social Media Cards if `proxy` is true.",
+ "The description of the short link. Will be used for Custom Social Media Cards if `proxy` is true.",
),
image: z
.string()
.nullable()
.describe(
- "The image of the short link generated via `api.dub.co/metatags`. Will be used for Custom Social Media Cards if `proxy` is true.",
+ "The image of the short link. Will be used for Custom Social Media Cards if `proxy` is true.",
),
video: z
.string()
diff --git a/apps/web/lib/zod/schemas/metatags.ts b/apps/web/lib/zod/schemas/metatags.ts
deleted file mode 100644
index cb7280f27c..0000000000
--- a/apps/web/lib/zod/schemas/metatags.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import z from "@/lib/zod";
-
-export const metaTagsSchema = z.object({
- title: z
- .string()
- .nullable()
- .describe("The meta title tag for the URL.")
- .openapi({
- example: "Dub.co - Link Management for Modern Marketing Teams",
- }),
- description: z
- .string()
- .nullable()
- .describe("The meta description tag for the URL.")
- .openapi({
- example: "Dub.co is the open-source link management infrastructure ...",
- }),
- image: z
- .string()
- .nullable()
- .describe("The OpenGraph image for the URL.")
- .openapi({ example: "https://assets.dub.co/thumbnail.jpg" }),
-});
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index f98cf13ca0..49bed7f523 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -165,30 +165,6 @@ module.exports = withAxiom({
}
),
),
- {
- source: "/metatags",
- has: [
- {
- type: "host",
- value: "dub.sh",
- },
- ],
- destination: "https://dub.co/tools/metatags",
- permanent: true,
- statusCode: 301,
- },
- {
- source: "/metatags",
- has: [
- {
- type: "host",
- value: "dub.co",
- },
- ],
- destination: "/tools/metatags",
- permanent: true,
- statusCode: 301,
- },
{
source: "/",
has: [
diff --git a/apps/web/tests/metatags/retrieve-metatags.test.ts b/apps/web/tests/links/retrieve-metatags.test.ts
similarity index 80%
rename from apps/web/tests/metatags/retrieve-metatags.test.ts
rename to apps/web/tests/links/retrieve-metatags.test.ts
index e223607399..bdf744ab6c 100644
--- a/apps/web/tests/metatags/retrieve-metatags.test.ts
+++ b/apps/web/tests/links/retrieve-metatags.test.ts
@@ -1,13 +1,12 @@
-import { MetaTag } from "@/lib/types";
import { expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
-test("GET /metatags", async (ctx) => {
+test("GET /links/metatags", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { http } = await h.init();
- const { status, data: metatags } = await http.get<MetaTag>({
- path: `/metatags`,
+ const { status, data: metatags } = await http.get({
+ path: "/links/metatags",
query: {
url: "https://dub.co",
},
diff --git a/apps/web/ui/links/link-builder/use-metatags.ts b/apps/web/ui/links/link-builder/use-metatags.ts
index 7cd2942aa2..374e67831f 100644
--- a/apps/web/ui/links/link-builder/use-metatags.ts
+++ b/apps/web/ui/links/link-builder/use-metatags.ts
@@ -42,7 +42,7 @@ export function useMetatags({ enabled = true }: { enabled?: boolean } = {}) {
// if url is valid, continue to generate metatags, else throw error and return null
new URL(debouncedUrl);
setGeneratingMetatags(true);
- fetch(`/api/metatags?url=${debouncedUrl}`).then(async (res) => {
+ fetch(`/api/links/metatags?url=${debouncedUrl}`).then(async (res) => {
if (res.status === 200) {
const results = await res.json();
const truncatedTitle = truncate(results.title, 120);
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 7ae6d61199..f6f7c7020d 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub.co",
- "version": "0.2.35",
+ "version": "0.2.36",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/packages/ui/src/link-preview.tsx b/packages/ui/src/link-preview.tsx
index 82f3a49f6f..3dc301a5a0 100644
--- a/packages/ui/src/link-preview.tsx
+++ b/packages/ui/src/link-preview.tsx
@@ -2,7 +2,7 @@
import { fetcher, getDomainWithoutWWW, getUrlFromString } from "@dub/utils";
import { Link2 } from "lucide-react";
-import { useRouter, useSearchParams } from "next/navigation";
+import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
@@ -10,7 +10,6 @@ import { useMediaQuery } from "./hooks";
import { LoadingCircle, Photo } from "./icons";
export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
- const router = useRouter();
const searchParams = useSearchParams();
const url =
defaultUrl || searchParams?.get("url") || "https://github.com/dubinc/dub";
@@ -24,7 +23,8 @@ export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
description: string | null;
image: string | null;
}>(
- debouncedUrl && `/api/metatags?url=${encodeURIComponent(debouncedUrl)}`,
+ debouncedUrl &&
+ `/api/links/metatags?url=${encodeURIComponent(debouncedUrl)}`,
fetcher,
{
revalidateOnFocus: false,
@@ -56,13 +56,6 @@ export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
className="block w-full rounded-md border-neutral-200 pl-10 text-sm text-neutral-900 placeholder-neutral-400 shadow-lg focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"
placeholder="Enter your URL"
defaultValue={url}
- onChange={(e) =>
- router.replace(
- `/tools/metatags${
- e.target.value.length > 0 ? `?url=${e.target.value}` : ""
- }`,
- )
- }
aria-invalid="true"
/>
</div>
diff --git a/packages/utils/src/constants/layout.ts b/packages/utils/src/constants/layout.ts
index c874cda1b9..e1fca2a6cc 100644
--- a/packages/utils/src/constants/layout.ts
+++ b/packages/utils/src/constants/layout.ts
@@ -8,6 +8,5 @@ export const ALL_TOOLS = [
{ name: "Google Link Shortener", slug: "google-link-shortener" },
{ name: "Amazon Link Shortener", slug: "amazon-link-shortener" },
{ name: "Figma Link Shortener", slug: "figma-link-shortener" },
- { name: "Metatags API", slug: "metatags" },
{ name: "Link Inspector", slug: "inspector" },
];
diff --git a/packages/utils/src/constants/main.ts b/packages/utils/src/constants/main.ts
index d2f6e607e7..ce6e1928ec 100644
--- a/packages/utils/src/constants/main.ts
+++ b/packages/utils/src/constants/main.ts
@@ -3,8 +3,6 @@ export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Dub.co";
export const SHORT_DOMAIN =
process.env.NEXT_PUBLIC_APP_SHORT_DOMAIN || "dub.sh";
-export const HOME_DOMAIN = `https://${process.env.NEXT_PUBLIC_APP_DOMAIN}`;
-
export const APP_HOSTNAMES = new Set([
`app.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,
`preview.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,
diff --git a/packages/utils/src/functions/construct-metadata.ts b/packages/utils/src/functions/construct-metadata.ts
index 32756a6de2..fecf617204 100644
--- a/packages/utils/src/functions/construct-metadata.ts
+++ b/packages/utils/src/functions/construct-metadata.ts
@@ -1,5 +1,4 @@
import { Metadata } from "next";
-import { HOME_DOMAIN } from "../constants";
export function constructMetadata({
title,
@@ -73,7 +72,7 @@ export function constructMetadata({
creator: "@dubdotco",
},
icons,
- metadataBase: new URL(HOME_DOMAIN),
+ metadataBase: new URL("https://dub.co"),
...((url || canonicalUrl) && {
alternates: {
canonical: url || canonicalUrl,