Skip to content

Commit

Permalink
✨ add cors middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed May 27, 2024
1 parent 6e27ede commit aa6a788
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions functions/grapher/_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Respond to OPTIONS method
export const onRequestOptions: PagesFunction = async () => {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Max-Age": "86400",
},
})
}

// Set CORS to all /api responses
export const onRequest: PagesFunction = async (context) => {
const response = await context.next()
response.headers.set("Access-Control-Allow-Origin", "*")
response.headers.set("Access-Control-Max-Age", "86400")
return response
}

0 comments on commit aa6a788

Please sign in to comment.