From 79ff113b6f731b51ffc1d39d0954eb41ddc5f102 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 27 Jun 2024 18:38:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=A8=E5=9F=9F=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/cors.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/middleware/cors.js b/middleware/cors.js index 6b94c23..7abb3c8 100644 --- a/middleware/cors.js +++ b/middleware/cors.js @@ -13,9 +13,13 @@ export function createCors() { if (opts.enabled) { let origin = req.headers['origin'] || req.headers['referer'] || '' let headers = req.headers['access-control-request-headers'] + + if (!origin) { + return next() + } let { hostname, host, protocol } = parse(origin) - if (opts.origin.length && hostname) { + if (opts.origin.length) { let pass = false for (let it of opts.origin) { if (hostname.endsWith(it)) {