/* * ============================================================ * CONFIGURAÇÕES PRINCIPAIS * ============================================================ */ const CHECKOUT_PAGE = "https://myangelcenter.com/checkout/"; const SALES_PAGE_NORMAL = "https://angelsaintapp.lovable.app/"; /* * COOKIE * * Criado ao acessar: * * https://healthnewsfr.com/salespage?_dst=true */ const COOKIE_NAME = "r_code"; const COOKIE_VALUE = "rasputin"; /* * 6 horas */ const COOKIE_DURATION_SECONDS = 6 * 60 * 60; /* * ============================================================ * UPSELLS * ============================================================ */ const UPSELLS = { "/up1": { normal: "https://myangelcenter.com/up1xmllllllllll", special: "https://myangelcenter.com/up1xmlllllllll-copia", }, "/up2": { normal: "https://myangelcenter.com/up2xmllllllllll", special: "https://myangelcenter.com/up2xmlllllllll-copia", }, "/up3": { normal: "https://myangelcenter.com/up3xmllllllllll", special: "https://myangelcenter.com/up3xmlllllllll-copia", }, }; /* * ============================================================ * FUNÇÕES AUXILIARES * ============================================================ */ /* * Faz: * * /up1 * /up1/ * * serem tratados da mesma forma. */ function normalizePath(pathname) { if ( pathname.length > 1 && pathname.endsWith("/") ) { return pathname.slice(0, -1); } return pathname; } /* * ============================================================ * LER COOKIE * ============================================================ */ function getCookie( request, cookieName ) { const cookieHeader = request.headers.get("cookie") || ""; const cookies = cookieHeader.split(";"); for (const cookie of cookies) { const separatorIndex = cookie.indexOf("="); if (separatorIndex === -1) { continue; } const name = cookie .slice(0, separatorIndex) .trim(); const value = cookie .slice(separatorIndex + 1) .trim(); if (name === cookieName) { try { return decodeURIComponent(value); } catch { return value; } } } return null; } /* * ============================================================ * CRIAR COOKIE * ============================================================ * * r_code=rasputin * * válido por 6 horas em healthnewsfr.com */ function createAuthorizedCookie() { return [ `${COOKIE_NAME}=${encodeURIComponent( COOKIE_VALUE )}`, "Path=/", `Max-Age=${COOKIE_DURATION_SECONDS}`, "HttpOnly", "Secure", "SameSite=Lax", ].join("; "); } /* * ============================================================ * APAGAR COOKIE * ============================================================ */ function createExpiredCookie() { return [ `${COOKIE_NAME}=`, "Path=/", "Max-Age=0", "HttpOnly", "Secure", "SameSite=Lax", ].join("; "); } /* * ============================================================ * CRIAR URL EXTERNA * ============================================================ * * Copia TODOS os parâmetros recebidos. * * Se removeDst = true: * não envia _dst para a página externa. */ function createTargetUrl( incomingUrl, targetAddress, removeDst = false ) { const targetUrl = new URL(targetAddress); for ( const [name, value] of incomingUrl.searchParams.entries() ) { /* * _dst só serve para nossa lógica interna. */ if ( removeDst && name === "_dst" ) { continue; } targetUrl.searchParams.append( name, value ); } return targetUrl; } /* * ============================================================ * PROXY * ============================================================ * * Busca a página externa e devolve seu conteúdo * mantendo healthnewsfr.com na barra. * * Também pode adicionar cabeçalhos extras, * como Set-Cookie. */ async function proxyPage( request, targetAddress, options = {} ) { const { removeDst = false, extraHeaders = {}, } = options; const incomingUrl = new URL(request.url); const targetUrl = createTargetUrl( incomingUrl, targetAddress, removeDst ); /* * Busca a página externa. */ const originResponse = await fetch( targetUrl.toString(), { method: "GET", redirect: "follow", headers: { Accept: request.headers.get("accept") || "text/html,application/xhtml+xml", "Accept-Language": request.headers.get( "accept-language" ) || "en-US,en;q=0.9", "User-Agent": request.headers.get( "user-agent" ) || "Mozilla/5.0", }, } ); /* * Trata erro da origem. */ if (!originResponse.ok) { throw new Error( `Página externa respondeu com status ${originResponse.status}` ); } /* * Obtém o HTML. */ let html = await originResponse.text(); /* * ========================================================== * BASE URL * ========================================================== * * Isso ajuda CSS, JS, imagens, fontes, * formulários e links relativos a usarem * o domínio original. */ if (/
]/i.test(html)) { if (/