Spaces:
Sleeping
Sleeping
xyzsun
commited on
Update index.js
Browse files
index.js
CHANGED
@@ -93,10 +93,21 @@ cron.schedule('*/2 * * * *', () => {
|
|
93 |
// 创建HTTP服务
|
94 |
const server = http.createServer((req, res) => {
|
95 |
if (req.url === '/') {
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
} else {
|
99 |
-
|
|
|
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 |
});
|