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; }