| const express = require("express"); |
| const axios = require("axios"); |
| const cron = require("node-cron"); |
|
|
| const app = express(); |
| const PORT = process.env.PORT || 7860; |
|
|
| |
| const PING_URL = "https://txtorg-newspa.hf.space/login"; |
| const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; |
| const STREAM_API_URL = "https://txtorg-stream.hf.space/timestamp?channel=AniTv"; |
| const SELF_URL = "https://pycra-pi.hf.space"; |
|
|
| |
| app.get("/", (req, res) => { |
| res.send("Keep-alive server is running! β
"); |
| }); |
|
|
| |
| const pingSite = async (url, retries = 3) => { |
| for (let attempt = 1; attempt <= retries; attempt++) { |
| try { |
| const response = await axios.get(url, { timeout: 5000 }); |
| console.log(`β
Pinged: ${url} | Status: ${response.status}`); |
| return; |
| } catch (error) { |
| console.error(`β Failed to ping: ${url} | Attempt ${attempt} of ${retries}`); |
| if (attempt < retries) { |
| await new Promise((resolve) => setTimeout(resolve, 5000)); |
| } |
| } |
| } |
| }; |
|
|
| |
| cron.schedule("*/7 * * * * *", async () => { |
| pingSite(PING_URL); |
| pingSite(CODE_API_URL); |
| pingSite(STREAM_API_URL); |
| pingSite(SELF_URL); |
| }); |
|
|
| |
| app.listen(PORT, () => { |
| console.log(`π Keep-alive server running at ${SELF_URL} on port ${PORT}`); |
| }); |