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(`
Редирект через ${redirectDelay / 1000} сек на ${fullUrl}
`); } catch (err) { console.error('Ошибка:', err.message); res.status(500).send(`${err.message}`);
}
});
app.listen(port, () => {
console.log(`🚀 Сервер запущен: http://localhost:${port}`);
console.log(`🔗 Пример: http://localhost:${port}/news`);
});