| const axios = require('axios'); |
| const moment = require('moment-timezone'); |
| const http = require('http'); |
| const cron = require('node-cron'); |
| const port = process.env.PORT || 7860; |
|
|
| |
| const webpages = [ |
| 'https://error418-oneapi.hf.space', |
| 'https://error418-alist.hf.space', |
| 'https://error418-logs.hf.space', |
| 'https://api.hongshi.us.kg', |
| 'https://error418-api-homepage.static.hf.space', |
| 'https://error418-keep.hf.space', |
| 'https://error418-bingai-pass.hf.space', |
| 'https://hongshi-files-chat2api.hf.space', |
| 'https://alist.hongshi-app.us.kg', |
| |
| ]; |
|
|
| |
| const urls = [ |
| 'https://www.google.com', |
| 'https://www.baidu.com', |
| |
| ]; |
|
|
| |
| const visit = async (url) => { |
| try { |
| const response = await axios.get(url); |
| console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Visited web successfully: ${url} --- Status: ${response.status}\n`); |
| } catch (error) { |
| console.error(`Failed to visit ${url}: ${error.message}\n`); |
| } |
| }; |
| const visitAll = async () => { |
| for (let url of urls) { |
| await visit(url); |
| } |
| }; |
|
|
| |
| const isWithinTime = () => { |
| const now = moment().tz('Asia/Hong_Kong'); |
| const hour = now.hour(); |
| if (hour >= 1 && hour < 6) { |
| return false; |
| } |
| return true; |
| }; |
|
|
| |
| const createServer = () => { |
| const server = http.createServer((req, res) => { |
| if (req.url === '/') { |
| res.writeHead(200, {'Content-Type': 'text/plain'}); |
| res.end('Hello world!'); |
| } else { |
| res.writeHead(404, {'Content-Type': 'text/plain'}); |
| res.end('404 Not Found'); |
| } |
| }); |
| server.listen(port, () => { |
| console.log(`Server started on port ${port}`); |
| }); |
| }; |
|
|
| |
| const main = async () => { |
| createServer(); |
| setInterval(async () => { |
| if (isWithinTime()) { |
| await visitAll(); |
| } else { |
| console.log(`Stop visiting at ${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}`); |
| } |
| }, 2 * 60 * 1000); |
| }; |
| main(); |
|
|
| |
| async function access(url) { |
| try { |
| const response = await axios.get(url); |
| console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited successfully: ${url} --- status:${response.status}`); |
| } catch (error) { |
| console.error(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Failed to visit ${url}, Error ${error.message}`); |
| } |
| } |
|
|
| async function batchVisit() { |
|
|
| for (let url of webpages) { |
| await access(url); |
| } |
| } |
| cron.schedule('*/2 * * * *', batchVisit); |