Browse Source

修改测试数据文件接口,把下载更换为返回页面

JiahengHe 2 months ago
parent
commit
8d787d089d
1 changed files with 9 additions and 5 deletions
  1. 9 5
      src/web.js

+ 9 - 5
src/web.js

@@ -160,16 +160,20 @@ function init() {
         const logPath = "./db/" + port + ".html";
         const latestFile = path.resolve(logPath);
         if (!fs.existsSync(latestFile)) {
-            return res.status(404).send('没有找到文件。');
+            res.writeHead(404, { 'Content-Type': 'text/plain' });
+            res.end('Not Found');
         }
 
-        // 设置下载响应
-        res.download(latestFile, err => {
+        // 读取HTML文件
+        fs.readFile(latestFile, (err, content) => {
             if (err) {
-                res.status(500).send('下载失败, 异常信息:', err);
+                res.writeHead(500, { 'Content-Type': 'text/plain' });
+                res.end('Internal Server Error');
+            } else {
+                res.writeHead(200, { 'Content-Type': 'text/html' });
+                res.end(content);
             }
         });
-
     })
 
     // 新策略-返回机器人状态