From 8ac0979c6734fdc57af38de109bf3bda4df79d71 Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 18 May 2026 16:45:13 +0000 Subject: [PATCH] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20autom=C3=A1tica:=202026?= =?UTF-8?q?-05-18=2016:45:13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-interface/server.js | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/web-interface/server.js b/web-interface/server.js index f5b27f4..21ffa26 100644 --- a/web-interface/server.js +++ b/web-interface/server.js @@ -3,6 +3,7 @@ const path = require('path'); const cors = require('cors'); const axios = require('axios'); const { exec, spawn } = require('child_process'); +const fs = require('fs'); const app = express(); const PORT = process.env.PORT || 3000; @@ -33,6 +34,62 @@ app.use(express.static(path.join(__dirname, 'public'), { } })); +// Middleware para injetar fix de roteador em sites clonados (SPAs como React, Vue, Angular, Vite) +app.use((req, res, next) => { + if (!req.path.startsWith('/api') && req.path !== '/' && req.path !== '/old') { + let urlPath = req.path; + if (!urlPath.match(/\.[a-zA-Z0-9]+$/)) { + if (!urlPath.endsWith('/')) urlPath += '/'; + urlPath += 'index.html'; + } + + if (urlPath.endsWith('.html')) { + const filePath = path.join(__dirname, '..', 'cloned-sites', urlPath); + if (fs.existsSync(filePath)) { + try { + let html = fs.readFileSync(filePath, 'utf8'); + if (!html.includes('__CLONEWEB_ROUTER_FIX__')) { + const injectScript = ` + + `; + if (html.includes('')) { + html = html.replace('', '' + injectScript); + } else { + html = injectScript + html; + } + } + res.setHeader('Content-Type', 'text/html'); + return res.send(html); + } catch (err) { + console.error('Erro ao injetar fix no HTML do clone:', err); + } + } + } + } + next(); +}); + // Serve cloned sites directory app.use(express.static(path.join(__dirname, '..', 'cloned-sites'), { setHeaders: (res, filePath) => {