Add CORS headers to API responses (#162)

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.
This commit is contained in:
MD. ABU SAYED authored and GitHub committed 2025-12-05 15:34:59 +08:00
1 parent 1e0f68721b
commit 64931bf3c4
1 file changed
+6
+6
View File
@@ -15,6 +15,9 @@ export default async function handler(req: NextRequest): Promise<Response> {
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<Response> {
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',
},
})
}