This commit is contained in:
蒋小陌 2024-10-14 17:45:05 +08:00
parent 9b88bedb80
commit c88e2f172d

View File

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