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.
pull/163/head
MD. ABU SAYED 2025-12-05 13:34:59 +06:00 committed by GitHub
parent 1e0f68721b
commit 64931bf3c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

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',
},
})
}