Skip to content

Commit

Permalink
feat: add cors support
Browse files Browse the repository at this point in the history
  • Loading branch information
sirily11 committed Aug 25, 2022
1 parent 3936771 commit 675a5a8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions functions/codeblock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,26 @@ export function handler({

export default {
async fetch(request: Request): Promise<Response> {
if (request.method === "OPTIONS") {
return new Response("", {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type",
},
});
}

const message = await request.json<Message>();
const response = handler(message);

return new Response(response.body, {
status: response.statusCode,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type",
},
});
},
Expand Down

0 comments on commit 675a5a8

Please sign in to comment.