Atualização automática: 2026-05-18 16:45:13

This commit is contained in:
Hermes
2026-05-18 16:45:13 +00:00
parent ef6dcc7c63
commit 8ac0979c67
+57
View File
@@ -3,6 +3,7 @@ const path = require('path');
const cors = require('cors'); const cors = require('cors');
const axios = require('axios'); const axios = require('axios');
const { exec, spawn } = require('child_process'); const { exec, spawn } = require('child_process');
const fs = require('fs');
const app = express(); const app = express();
const PORT = process.env.PORT || 3000; 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 = `
<script id="__CLONEWEB_ROUTER_FIX__">
(function() {
try {
const originalPathname = Object.getOwnPropertyDescriptor(Location.prototype, 'pathname').get;
Object.defineProperty(Location.prototype, 'pathname', {
get: function() {
const path = originalPathname.call(this);
if (path !== '/' && path !== '/index.html') {
return '/';
}
return path;
},
set: function(val) {
window.location.assign(val);
}
});
console.log('🚀 [CloneWeb] SPA Router fix initialized. Simulating root pathname /');
} catch(e) {
console.error('❌ [CloneWeb] Failed to initialize router fix:', e);
}
})();
</script>
`;
if (html.includes('<head>')) {
html = html.replace('<head>', '<head>' + 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 // Serve cloned sites directory
app.use(express.static(path.join(__dirname, '..', 'cloned-sites'), { app.use(express.static(path.join(__dirname, '..', 'cloned-sites'), {
setHeaders: (res, filePath) => { setHeaders: (res, filePath) => {