Update server.js
Browse files
server.js
CHANGED
|
@@ -3,11 +3,12 @@ const axios = require("axios");
|
|
| 3 |
const cron = require("node-cron");
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
-
const PORT = process.env.PORT ||
|
| 7 |
|
| 8 |
// Target URLs (Hugging Face Spaces)
|
| 9 |
const PING_URL = "https://txtorg-newspa.hf.space/login"; // First API
|
| 10 |
const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; // Second API
|
|
|
|
| 11 |
const SELF_URL = "https://pycra-pi.hf.space"; // Self-ping URL
|
| 12 |
|
| 13 |
// Check server status
|
|
@@ -17,26 +18,29 @@ app.get("/", (req, res) => {
|
|
| 17 |
|
| 18 |
// Function to ping a site with retries
|
| 19 |
const pingSite = async (url, retries = 3) => {
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
console.
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
};
|
| 31 |
|
| 32 |
// **Auto Ping Every 7 Seconds**
|
| 33 |
-
cron.schedule("*/7 * * * * *", () => {
|
| 34 |
pingSite(PING_URL); // Ping first API
|
| 35 |
pingSite(CODE_API_URL); // Ping second API
|
|
|
|
| 36 |
pingSite(SELF_URL); // Ping itself
|
| 37 |
});
|
| 38 |
|
| 39 |
// Start Express server
|
| 40 |
app.listen(PORT, () => {
|
| 41 |
-
console.log(`π Keep-alive server running at ${SELF_URL}`);
|
| 42 |
});
|
|
|
|
| 3 |
const cron = require("node-cron");
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
+
const PORT = process.env.PORT || 7860;
|
| 7 |
|
| 8 |
// Target URLs (Hugging Face Spaces)
|
| 9 |
const PING_URL = "https://txtorg-newspa.hf.space/login"; // First API
|
| 10 |
const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; // Second API
|
| 11 |
+
const STREAM_API_URL = "https://txtorg-stream.hf.space/timestamp?channel=AniTv"; // New API
|
| 12 |
const SELF_URL = "https://pycra-pi.hf.space"; // Self-ping URL
|
| 13 |
|
| 14 |
// Check server status
|
|
|
|
| 18 |
|
| 19 |
// Function to ping a site with retries
|
| 20 |
const pingSite = async (url, retries = 3) => {
|
| 21 |
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
| 22 |
+
try {
|
| 23 |
+
const response = await axios.get(url, { timeout: 5000 });
|
| 24 |
+
console.log(`β
Pinged: ${url} | Status: ${response.status}`);
|
| 25 |
+
return; // Success, exit function
|
| 26 |
+
} catch (error) {
|
| 27 |
+
console.error(`β Failed to ping: ${url} | Attempt ${attempt} of ${retries}`);
|
| 28 |
+
if (attempt < retries) {
|
| 29 |
+
await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait before retrying
|
| 30 |
+
}
|
| 31 |
}
|
| 32 |
}
|
| 33 |
};
|
| 34 |
|
| 35 |
// **Auto Ping Every 7 Seconds**
|
| 36 |
+
cron.schedule("*/7 * * * * *", async () => {
|
| 37 |
pingSite(PING_URL); // Ping first API
|
| 38 |
pingSite(CODE_API_URL); // Ping second API
|
| 39 |
+
pingSite(STREAM_API_URL); // Ping new API
|
| 40 |
pingSite(SELF_URL); // Ping itself
|
| 41 |
});
|
| 42 |
|
| 43 |
// Start Express server
|
| 44 |
app.listen(PORT, () => {
|
| 45 |
+
console.log(`π Keep-alive server running at ${SELF_URL} on port ${PORT}`);
|
| 46 |
});
|