const https = require('https');
module.exports = async (req, res) => {
try {
const path = req.url === '/' ? '' : req.url;
const targetUrl = 'https://embedflix.top/tv/' + path;
https.get(targetUrl, {
headers: {
'User-Agent': req.headers['user-agent'] || 'Mozilla/5.0',
'Referer': 'https://embedflix.top/tv/',
}
}, (resp) => {
let data = '';
resp.on('data', chunk => data += chunk);
resp.on('end', () => {
try {
// Reescreve links para manter no domínio Vercel
data = data
.replace(/https:\/\/embedflix.top\.top\/tv\//g, '/')
.replace(/href='\/([^']+)'/g, "href='/$1'")
.replace(/href="\/([^"]+)"/g, 'href="/$1"')
.replace(/action="\/([^"]+)"/g, 'action="/$1"')
.replace(/ ]*>/gi, '');
// Remover ou alterar o título e o ícone
data = data
.replace(/[^<]*<\/title>/, 'Meu Site ') // Coloque aqui o título desejado
.replace(/]*rel=["']icon["'][^>]*>/gi, ''); // Remove o ícone
// Injeção segura de banner no final do body com verificação
let finalHtml;
if (data.includes('