-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
route.ts
42 lines (37 loc) · 1.05 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { ratelimitOrThrow } from "@/lib/api/utils";
import { getUrlQuerySchema } from "@/lib/zod/schemas/links";
import { NextRequest, NextResponse } from "next/server";
import { getMetaTags } from "./utils";
export const runtime = "edge";
export async function GET(req: NextRequest) {
try {
const { url } = getUrlQuerySchema.parse({
url: req.nextUrl.searchParams.get("url"),
});
await ratelimitOrThrow(req, "metatags");
const metatags = await getMetaTags(url);
return NextResponse.json(
{
...metatags,
poweredBy: "Dub.co - Link management for modern marketing teams",
},
{
headers: {
"Access-Control-Allow-Origin": "*",
},
},
);
} catch (error) {
return handleAndReturnErrorResponse(error);
}
}
export function OPTIONS() {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
},
});
}