Spaces:
Sleeping
Sleeping
xyzsun
commited on
Update index.js
Browse files
index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
const axios = require('axios');
|
2 |
const http = require('http');
|
|
|
3 |
const cron = require('node-cron');
|
4 |
const port = process.env.PORT || 7860;
|
5 |
const moment = require('moment-timezone');
|
@@ -93,20 +94,20 @@ cron.schedule('*/2 * * * *', () => {
|
|
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 |
-
//
|
110 |
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
111 |
res.end('Not Found\n');
|
112 |
}
|
|
|
1 |
const axios = require('axios');
|
2 |
const http = require('http');
|
3 |
+
const fs = require('fs');
|
4 |
const cron = require('node-cron');
|
5 |
const port = process.env.PORT || 7860;
|
6 |
const moment = require('moment-timezone');
|
|
|
94 |
// 创建HTTP服务
|
95 |
const server = http.createServer((req, res) => {
|
96 |
if (req.url === '/') {
|
97 |
+
// 读取 index.html 文件的内容
|
98 |
fs.readFile('index.html', 'utf8', (err, data) => {
|
99 |
if (err) {
|
100 |
+
// 如果读取文件出错,返回 404
|
101 |
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
102 |
res.end('Not Found\n');
|
103 |
} else {
|
104 |
+
// 返回 HTML 内容
|
105 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
106 |
res.end(data);
|
107 |
}
|
108 |
});
|
109 |
} else {
|
110 |
+
// 返回其他路径的 404
|
111 |
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
112 |
res.end('Not Found\n');
|
113 |
}
|