From c88e2f172d0033c2c07c5e0def08c9c872bb6124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=92=8B=E5=B0=8F=E9=99=8C?= <xiaomo.drip@gmail.com>
Date: Mon, 14 Oct 2024 17:45:05 +0800
Subject: [PATCH] 111

---
 index.js | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/index.js b/index.js
index 0fd4377..41f9e60 100644
--- a/index.js
+++ b/index.js
@@ -58,15 +58,20 @@ setInterval(() => {
 const server = http.createServer(async (req, res) => {
 
     req.url = req.url.replace(/\/{2,}/g, '/');
+    const parsedUrl = url.parse(req.url, true);
+    const reqPath = parsedUrl.pathname;
+    const sign = parsedUrl.query.sign || '';
 
-    if (req.url === '/favicon.ico') {
+    // 处理根路径请求
+
+    if (reqPath === '/favicon.ico') {
         res.writeHead(204);
         res.end();
         return;
     }
 
     // 返回 endpoint, 缓存目录, 缓存数量, 用于监听服务是否正常运行
-    if (req.url === '/endpoint') {
+    if (reqPath === '/endpoint') {
         res.writeHead(200, { 'Content-Type': 'application/json' });
         res.end(JSON.stringify({
             code: 200,
@@ -81,13 +86,9 @@ const server = http.createServer(async (req, res) => {
         return;
     }
 
-    const parsedUrl = url.parse(req.url, true);
-    const reqPath = parsedUrl.pathname;
-    const sign = parsedUrl.query.sign || '';
-
     if (!sign || reqPath === '/') {
         res.writeHead(400, { 'Content-Type': 'text/plain' });
-        res.end('Bad Request: Missing sign or path (' + req.url + ')');
+        res.end('Bad Request: Missing sign or path (' + reqPath + ')');
         return;
     }