Update app.js

This commit is contained in:
甬哥侃侃侃ygkkk
2025-01-27 12:30:50 +08:00
committed by GitHub
parent 9d0467fbaa
commit 64cfa177d6
+8 -6
View File
@@ -3,12 +3,11 @@ const express = require("express");
const { exec } = require('child_process'); const { exec } = require('child_process');
const app = express(); const app = express();
app.use(express.json()); app.use(express.json());
app.get("/up", function (req, res) { const commandToRun = "cd ~ && bash serv00keep.sh";
const commandToRun = "cd ~ && bash serv00keep.sh"; function runCustomCommand() {
exec(commandToRun, function (err, stdout, stderr) { exec(commandToRun, function (err, stdout, stderr) {
if (err) { if (err) {
console.log("命令执行错误: " + err); console.log("命令执行错误: " + err);
res.status(500).send("服务器错误");
return; return;
} }
if (stderr) { if (stderr) {
@@ -16,8 +15,11 @@ app.get("/up", function (req, res) {
} }
console.log("命令执行成功:\n" + stdout); console.log("命令执行成功:\n" + stdout);
}); });
}
res.type("html").send("<pre>Serv00网页保活启动:Serv00!一柱擎天!UPUPUP</pre>"); setInterval(runCustomCommand, 3 * 60 * 1000); // 3 分钟 = 3 * 60 * 1000 毫秒
app.get("/up", function (req, res) {
runCustomCommand();
res.type("html").send("<pre>Serv00网页保活启动:Serv00UPUPUP</pre>");
}); });
app.use((req, res, next) => { app.use((req, res, next) => {
if (req.path === '/up') { if (req.path === '/up') {
@@ -25,7 +27,7 @@ app.use((req, res, next) => {
} }
res.status(404).send('把浏览器地址改为:http://name.name.serv00.net/up 这样才能启动Serv00网页保活'); res.status(404).send('把浏览器地址改为:http://name.name.serv00.net/up 这样才能启动Serv00网页保活');
}); });
app.listen(3000, () => { app.listen(3000, () => {
console.log("服务器已启动,监听端口 3000"); console.log("服务器已启动,监听端口 3000");
runCustomCommand();
}); });