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
parent
1e0f68721b
commit
64931bf3c4
|
|
@ -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',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue