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.

Merge branch 'main' into pr/453

Steven Tey7cf1753a138d
diff --cc apps/web/app/api/edge/metatags/utils.ts
index dc90b1faf5,283667c535..6394a1bc57
--- a/apps/web/app/api/edge/metatags/utils.ts
+++ b/apps/web/app/api/edge/metatags/utils.ts
@@@ -1,57 -1,10 +1,10 @@@
- import { ratelimit, recordMetatags } from "@/lib/upstash";
- import { LOCALHOST_IP, isValidUrl } from "@dub/utils";
- import { ipAddress } from "@vercel/edge";
- import { getToken } from "next-auth/jwt";
- import { NextFetchEvent, NextRequest } from "next/server";
import { parse } from "node-html-parser";
+import he from "he";
+ import { recordMetatags } from "@/lib/upstash";
+ import { isValidUrl } from "@dub/utils";
-import { NextFetchEvent } from "next/server";
+ import { internal_runWithWaitUntil as waitUntil } from "next/dist/server/web/internal-edge-wait-until";
- export const config = {
- runtime: "edge",
- };
-
- export default async function handler(req: NextRequest, ev: NextFetchEvent) {
- if (req.method === "GET") {
- const url = req.nextUrl.searchParams.get("url");
- if (!url || !isValidUrl(url)) {
- return new Response("Invalid URL", { status: 400 });
- }
-
- // Rate limit if user is not logged in
- const session = await getToken({
- req,
- secret: process.env.NEXTAUTH_SECRET,
- });
- if (!session?.email) {
- const ip = ipAddress(req) || LOCALHOST_IP;
- const { success } = await ratelimit().limit(ip);
- if (!success) {
- return new Response("Don't DDoS me pls 🥺", { status: 429 });
- }
- }
-
- const metatags = await getMetaTags(url, ev);
- return new Response(JSON.stringify(metatags), {
- status: 200,
- headers: {
- "Content-Type": "application/json",
- "Access-Control-Allow-Origin": "*",
- },
- });
- } else if (req.method === "OPTIONS") {
- return new Response(null, {
- status: 204,
- headers: {
- "Access-Control-Allow-Origin": "*",
- "Access-Control-Allow-Methods": "GET, OPTIONS",
- },
- });
- } else {
- return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
- }
- }
-
- const getHtml = async (url: string) => {
+ export const getHtml = async (url: string) => {
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000); // timeout if it takes longer than 5 seconds