From 8df0b26aa849d9a0575f07642fc25204f1964986 Mon Sep 17 00:00:00 2001 From: "MD. ABU SAYED" Date: Thu, 4 Dec 2025 13:37:59 +0600 Subject: [PATCH] Add CORS headers to API responses The API for status is showing CORS issue: "Response body is not available to scripts (Reason: CORS Missing Allow Origin)" when using from other domain/localhost. To solve this ,CORS header is added. It also possible to specify allowed domain in Env Var in cloudflare and call them directly. --- pages/api/data.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/api/data.ts b/pages/api/data.ts index ba52661..fd7fe1e 100644 --- a/pages/api/data.ts +++ b/pages/api/data.ts @@ -15,6 +15,9 @@ export default async function handler(req: NextRequest): Promise { status: 500, headers: { 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', }, }) } @@ -42,6 +45,9 @@ export default async function handler(req: NextRequest): Promise { return new Response(JSON.stringify(ret), { headers: { 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', }, }) }