From 68af480cca26561b49aaf462de6bf7451b0251f4 Mon Sep 17 00:00:00 2001 From: S1rius Date: Sat, 8 Feb 2025 18:58:55 +0800 Subject: [PATCH] Update stats.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决api跨域报错问题 --- src/pages/api/websites/[websiteId]/stats.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/api/websites/[websiteId]/stats.ts b/src/pages/api/websites/[websiteId]/stats.ts index dfc9198df..ff999086e 100644 --- a/src/pages/api/websites/[websiteId]/stats.ts +++ b/src/pages/api/websites/[websiteId]/stats.ts @@ -60,6 +60,11 @@ export default async ( const { websiteId, compare } = req.query; + // 处理 OPTIONS 请求 + if (req.method === 'OPTIONS') { + return res.status(200).end(); // 返回 200 OK 表示允许跨域 + } + if (req.method === 'GET') { if (!(await canViewWebsite(req.auth, websiteId))) { return unauthorized(res);