From 582977fc7a10e963c21ae37c4283b163c93abb3a Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 18 May 2026 18:11:46 +0000 Subject: [PATCH] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20autom=C3=A1tica:=202026?= =?UTF-8?q?-05-18=2018:11:46?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-interface/server.js | 98 +++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/web-interface/server.js b/web-interface/server.js index fc6b51f..567706e 100644 --- a/web-interface/server.js +++ b/web-interface/server.js @@ -34,7 +34,7 @@ app.use(express.static(path.join(__dirname, 'public'), { } })); -// Middleware para injetar fix de roteador em sites clonados (SPAs como React, Vue, Angular, Vite) +// Middleware para injetar fix de roteador em sites clonados (SPAs como React, Vue, Angular, Vite) e reescrever JS app.use((req, res, next) => { if (!req.path.startsWith('/api') && req.path !== '/' && req.path !== '/old') { let urlPath = req.path; @@ -48,6 +48,7 @@ app.use((req, res, next) => { urlPath += 'index.html'; } + // Interceptação de arquivos HTML (Camada 1 - DOM Mock Universal) if (urlPath.endsWith('.html')) { const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath); if (fs.existsSync(filePath)) { @@ -58,32 +59,50 @@ app.use((req, res, next) => { @@ -115,6 +134,29 @@ app.use((req, res, next) => { } } } + + // Interceptação de arquivos JS de sites clonados (Camada 2 - JS Rewriter Supremo) + if (urlPath.endsWith('.js') && (urlPath.includes('_202') || urlPath.includes('/cloned-sites/'))) { + const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath); + if (fs.existsSync(filePath)) { + try { + let jsContent = fs.readFileSync(filePath, 'utf8'); + + // Substitui chamadas diretas a window.location.pathname e location.pathname + jsContent = jsContent.replace(/window\.location\.pathname/g, '(window.__mockLocationPathname || window.location.pathname)'); + jsContent = jsContent.replace(/location\.pathname/g, '(window.__mockLocationPathname || window.location.pathname)'); + + // Substitui chamadas diretas a window.location.href e location.href + jsContent = jsContent.replace(/window\.location\.href/g, '(window.__mockLocationHref || window.location.href)'); + jsContent = jsContent.replace(/location\.href/g, '(window.__mockLocationHref || window.location.href)'); + + res.setHeader('Content-Type', 'application/javascript'); + return res.send(jsContent); + } catch (err) { + console.error('Erro ao reescrever JS do clone:', err); + } + } + } } next(); });