Skip to content

Commit

Permalink
handle OPTIONS request
Browse files Browse the repository at this point in the history
  • Loading branch information
stepandel committed Sep 25, 2023
1 parent 8c6b138 commit 14e049e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/worker/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export async function fetch(request: Request, env: Env, ctx: ExecutionContext) {
// ----------------

if (url.pathname.startsWith("/api/")) {
if (request.method === "OPTIONS") {
return createResponse({}, 204);
}

const path = url.pathname.split("/").slice(1);

switch (path[1]) {
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/worker/rpgfApi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function createResponse(
"content-type": "application/json",
"Access-Control-Allow-Origin": "*", // TODO: Update to only whitelisted domains
"Access-Control-Allow-Methods": "GET,HEAD,POST,UPDATE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Cookie",
"Access-Control-Max-Age": "86400",
"Access-Control-Allow-Credentials": "true",
"Cache-Control": "no-cache",
...headers,
},
});
Expand Down

0 comments on commit 14e049e

Please sign in to comment.