From 163e471bb41a257269395a2b624c32bf6dafab2e Mon Sep 17 00:00:00 2001 From: alan <67932758+alan16742@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:52:27 +0800 Subject: [PATCH] fix: preflight request --- back-end-cf/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/back-end-cf/index.js b/back-end-cf/index.js index 81035100..7eecdc76 100644 --- a/back-end-cf/index.js +++ b/back-end-cf/index.js @@ -52,6 +52,18 @@ async function handleRequest(request) { return Response.redirect(url, 302); } + // preflight + if(request.method === 'OPTIONS') { + return new Response(null, { + status: 204, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Max-Age': '86400', + } + }); + } + const returnHeaders = { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'max-age=3600',