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.pull/162/head
parent
1e0f68721b
commit
8df0b26aa8
|
|
@ -15,6 +15,9 @@ export default async function handler(req: NextRequest): Promise<Response> {
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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), {
|
return new Response(JSON.stringify(ret), {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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