From 05088cfad0deb71c638993a67ccf0e24f80d9c6c Mon Sep 17 00:00:00 2001 From: x-dr Date: Wed, 7 Feb 2024 22:27:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=84=E7=90=86OPTIONS=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/create.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/functions/create.js b/functions/create.js index b9b2c01..88f5d53 100644 --- a/functions/create.js +++ b/functions/create.js @@ -15,7 +15,19 @@ function generateRandomString(length) { return result; } -export async function onRequestPost(context) { + +export async function onRequest(context) { + if (context.request.method === 'OPTIONS') { + return new Response(null, { + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Max-Age': '86400', // 24小时 + }, + }); + } +// export async function onRequestPost(context) { const { request, env } = context; const originurl = new URL(request.url); const clientIP = request.headers.get("x-forwarded-for") || request.headers.get("clientIP");