perf: 支持跨域请求 (#98)

Co-authored-by: GH Action - Upstream Sync <action@github.com>
This commit is contained in:
xiaoQQyaandGH Action - Upstream Sync authored and GitHub committed 2025-11-22 07:51:03 +08:00
1 parent dd81ac0298
commit 61212367f5
2 files changed
+17 -4

No files matched your search

+8 -2
View File
@@ -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": "*"
}
});
}
+9 -2
View File
@@ -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 ---