Atualização automática: 2026-05-18 18:11:46
This commit is contained in:
+61
-19
@@ -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) => {
|
||||
<script id="__CLONEWEB_ROUTER_FIX__">
|
||||
(function() {
|
||||
try {
|
||||
const originalPathname = Object.getOwnPropertyDescriptor(Location.prototype, 'pathname').get;
|
||||
const originalHref = Object.getOwnPropertyDescriptor(Location.prototype, 'href').get;
|
||||
window.__mockLocationPathname = '/';
|
||||
window.__mockLocationHref = window.location.protocol + '//' + window.location.host + '/';
|
||||
|
||||
Object.defineProperty(Location.prototype, 'pathname', {
|
||||
let targetObj = window.location;
|
||||
let proto = Object.getPrototypeOf(targetObj);
|
||||
let pathDesc = null;
|
||||
let hrefDesc = null;
|
||||
|
||||
while (proto && (!pathDesc || !hrefDesc)) {
|
||||
if (!pathDesc) pathDesc = Object.getOwnPropertyDescriptor(proto, 'pathname');
|
||||
if (!hrefDesc) hrefDesc = Object.getOwnPropertyDescriptor(proto, 'href');
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
if (!pathDesc) pathDesc = Object.getOwnPropertyDescriptor(targetObj, 'pathname');
|
||||
if (!hrefDesc) hrefDesc = Object.getOwnPropertyDescriptor(targetObj, 'href');
|
||||
|
||||
if (pathDesc && pathDesc.configurable) {
|
||||
const origGet = pathDesc.get;
|
||||
Object.defineProperty(proto || targetObj, 'pathname', {
|
||||
get: function() {
|
||||
const path = originalPathname.call(this);
|
||||
if (path !== '/' && path !== '/index.html' && (path.includes('_202') || path.includes('/cloned-sites/'))) {
|
||||
const p = origGet ? origGet.call(this) : this.pathname;
|
||||
if (p !== '/' && p !== '/index.html' && (p.includes('_202') || p.includes('/cloned-sites/'))) {
|
||||
return '/';
|
||||
}
|
||||
return path;
|
||||
return p;
|
||||
},
|
||||
set: function(val) {
|
||||
window.location.assign(val);
|
||||
}
|
||||
set: pathDesc.set || function(v) { window.location.assign(v); }
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(Location.prototype, 'href', {
|
||||
if (hrefDesc && hrefDesc.configurable) {
|
||||
const origHrefGet = hrefDesc.get;
|
||||
Object.defineProperty(proto || targetObj, 'href', {
|
||||
get: function() {
|
||||
const href = originalHref.call(this);
|
||||
if (href.includes('_202') || href.includes('/cloned-sites/')) {
|
||||
const url = new URL(href);
|
||||
return url.protocol + '//' + url.host + '/';
|
||||
}
|
||||
return href;
|
||||
const h = origHrefGet ? origHrefGet.call(this) : this.href;
|
||||
if (h.includes('_202') || h.includes('/cloned-sites/')) {
|
||||
const u = new URL(h);
|
||||
return u.protocol + '//' + u.host + '/';
|
||||
}
|
||||
return h;
|
||||
},
|
||||
set: hrefDesc.set || function(v) { window.location.assign(v); }
|
||||
});
|
||||
}
|
||||
|
||||
const OriginalURL = window.URL;
|
||||
window.URL = function(url, base) {
|
||||
@@ -95,9 +114,9 @@ app.use((req, res, next) => {
|
||||
window.URL.prototype = OriginalURL.prototype;
|
||||
Object.assign(window.URL, OriginalURL);
|
||||
|
||||
console.log('🚀 [CloneWeb] Ultimate SPA Router fix initialized. Simulating root pathname /');
|
||||
console.log('🚀 [CloneWeb] Ultimate SPA Router fix initialized successfully (Cross-browser Gecko/Blink support).');
|
||||
} catch(e) {
|
||||
console.error('❌ [CloneWeb] Failed to initialize router fix:', e);
|
||||
console.error('⚠️ [CloneWeb] DOM mock fallback active. Using __mockLocationPathname. Error:', e);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user