From 61212367f5c880d0e97fb14bb78701a1b4c52f0a Mon Sep 17 00:00:00 2001 From: xiaoQQya <46475319+xiaoQQya@users.noreply.github.com> Date: Sat, 22 Nov 2025 07:51:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=94=AF=E6=8C=81=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=20(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: GH Action - Upstream Sync --- danmu_api/utils/http-util.js | 10 ++++++++-- danmu_api/worker.js | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/danmu_api/utils/http-util.js b/danmu_api/utils/http-util.js index 873a5ae..edae845 100644 --- a/danmu_api/utils/http-util.js +++ b/danmu_api/utils/http-util.js @@ -300,7 +300,10 @@ export async function getPageTitle(url) { export function jsonResponse(data, status = 200) { return new Response(JSON.stringify(data), { status, - headers: { "Content-Type": "application/json" }, + headers: { + "Content-Type": "application/json", + "Access-Control-Allow-Origin": "*" + } }); } @@ -313,7 +316,10 @@ export function xmlResponse(data, status = 200) { // 直接返回 XML 字符串作为 Response 的 body return new Response(data, { status, - headers: { "Content-Type": "application/xml" }, + headers: { + "Content-Type": "application/xml", + "Access-Control-Allow-Origin": "*" + } }); } diff --git a/danmu_api/worker.js b/danmu_api/worker.js index 4001883..9336599 100644 --- a/danmu_api/worker.js +++ b/danmu_api/worker.js @@ -53,8 +53,15 @@ async function handleRequest(req, env, deployPlatform, clientIp) { return handleHomepage(); } - if (path === "/favicon.ico" || path === "/robots.txt") { - return new Response(null, { status: 204 }); + if (path === "/favicon.ico" || path === "/robots.txt" || method === "OPTIONS") { + return new Response(null, { + status: 204, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization, User-Agent" + } + }); } // --- 校验 token ---