xyzsun commited on
Commit
1b93e5e
·
verified ·
1 Parent(s): 3fec24b

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +14 -3
index.js CHANGED
@@ -93,10 +93,21 @@ cron.schedule('*/2 * * * *', () => {
93
  // 创建HTTP服务
94
  const server = http.createServer((req, res) => {
95
  if (req.url === '/') {
96
- res.writeHead(200, {'Content-Type': 'text/plain'});
97
- res.end('Hello, World!\n');
 
 
 
 
 
 
 
 
 
 
98
  } else {
99
- res.writeHead(404, {'Content-Type': 'text/plain'});
 
100
  res.end('Not Found\n');
101
  }
102
  });
 
93
  // 创建HTTP服务
94
  const server = http.createServer((req, res) => {
95
  if (req.url === '/') {
96
+ // 读取index.html文件内容
97
+ fs.readFile('index.html', 'utf8', (err, data) => {
98
+ if (err) {
99
+ // 如果读取文件出错,返回404
100
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
101
+ res.end('Not Found\n');
102
+ } else {
103
+ // 返回HTML内容
104
+ res.writeHead(200, { 'Content-Type': 'text/html' });
105
+ res.end(data);
106
+ }
107
+ });
108
  } else {
109
+ // 返回404
110
+ res.writeHead(404, { 'Content-Type': 'text/plain' });
111
  res.end('Not Found\n');
112
  }
113
  });