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.

add cors to qr code API

Steven Tey58efa7164e73
diff --git a/apps/web/app/api/metatags/route.ts b/apps/web/app/api/metatags/route.ts
index 9bb1bdec15..683349fd63 100644
--- a/apps/web/app/api/metatags/route.ts
+++ b/apps/web/app/api/metatags/route.ts
@@ -6,6 +6,11 @@ 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 { url } = getUrlQuerySchema.parse({
@@ -21,22 +26,17 @@ export async function GET(req: NextRequest) {
poweredBy: "Dub.co - Link management for modern marketing teams",
},
{
- headers: {
- "Access-Control-Allow-Origin": "*",
- },
+ headers: CORS_HEADERS,
},
);
} catch (error) {
- return handleAndReturnErrorResponse(error);
+ return handleAndReturnErrorResponse(error, CORS_HEADERS);
}
}
export function OPTIONS() {
return new Response(null, {
status: 204,
- headers: {
- "Access-Control-Allow-Origin": "*",
- "Access-Control-Allow-Methods": "GET, OPTIONS",
- },
+ headers: CORS_HEADERS,
});
}
diff --git a/apps/web/app/api/qr/route.tsx b/apps/web/app/api/qr/route.tsx
index 52ba82b35f..153cfe5e98 100644
--- a/apps/web/app/api/qr/route.tsx
+++ b/apps/web/app/api/qr/route.tsx
@@ -9,6 +9,11 @@ import { NextRequest } from "next/server";
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 params = getSearchParams(req.url);
@@ -62,9 +67,17 @@ export async function GET(req: NextRequest) {
{
width: size,
height: size,
+ headers: CORS_HEADERS,
},
);
} catch (error) {
- return handleAndReturnErrorResponse(error);
+ return handleAndReturnErrorResponse(error, CORS_HEADERS);
}
}
+
+export function OPTIONS() {
+ return new Response(null, {
+ status: 204,
+ headers: CORS_HEADERS,
+ });
+}