This commit is contained in:
2025-10-02 12:32:57 +00:00
commit 93b8fd9d80
6 changed files with 115 additions and 0 deletions

51
server.js Normal file
View File

@@ -0,0 +1,51 @@
import express from 'express';
import axios from 'axios';
import * as cheerio from 'cheerio';
import fs from 'fs';
const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8'));
const { port, targetUrl, auth, redirectDelay, timeout, userAgent } = config;
const app = express();
app.get('*', async (req, res) => {
try {
const path = req.path === '/' ? '' : req.path;
const fullUrl = new URL(path, targetUrl).toString();
const response = await axios.get(fullUrl, {
auth, timeout,
headers: {'User-Agent': userAgent}
});
const $ = cheerio.load(response.data);
const metas = [];
$('meta').each((_, el) => {metas.push(el.attribs);});
res.send(`
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Meta Redirect</title>
${metas.map(m => `<meta ${Object.entries(m).map(([k, v]) => `${k}="${v}"`).join(' ')}>`).join('\n')}
<script>
setTimeout(() => {window.location.href = ${JSON.stringify(fullUrl)};}, ${redirectDelay});
</script>
</head>
<body>
<h1>Anix</h1>
<p>Редирект через ${redirectDelay / 1000} сек на <a href="${fullUrl}">${fullUrl}</a></p>
</body>
</html>
`);
} catch (err) {
console.error('Ошибка:', err.message);
res.status(500).send(`<h1>Ошибка при загрузке ${req.path}</h1><pre>${err.message}</pre>`);
}
});
app.listen(port, () => {
console.log(`🚀 Сервер запущен: http://localhost:${port}`);
console.log(`🔗 Пример: http://localhost:${port}/news`);
});