| import express from "express"; |
| import axios from "axios"; |
| import cors from "cors"; |
|
|
| const app = express(); |
|
|
| |
| app.use(cors()); |
|
|
| |
| app.use(express.json()); |
|
|
| |
| app.get("/", (req, res) => res.send("π₯ Advanced Proxy Server Live")); |
|
|
| |
| app.get("/proxy", async (req, res) => { |
| const { url, matchId, home, away, referer } = req.query; |
| |
| if (!url) return res.status(400).send("β Missing ?url param"); |
|
|
| const targetUrl = decodeURIComponent(url); |
| |
| |
| const customReferer = referer || |
| (matchId && home && away |
| ? `https://www.808ball6.com/football/${matchId}-${home}-vs-${away}.html` |
| : "https://www.808ball6.com/"); |
|
|
| |
| const urlObj = new URL(targetUrl); |
| const targetOrigin = `${urlObj.protocol}//${urlObj.hostname}`; |
|
|
| try { |
| const response = await axios.get(targetUrl, { |
| headers: { |
| |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", |
| |
| |
| "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", |
| "Accept-Language": "en-US,en;q=0.9,es;q=0.8,fr;q=0.7", |
| "Accept-Encoding": "gzip, deflate, br, zstd", |
| |
| |
| "Referer": customReferer, |
| "Origin": targetOrigin, |
| |
| |
| "Connection": "keep-alive", |
| |
| |
| "Sec-Fetch-Dest": "iframe", |
| "Sec-Fetch-Mode": "navigate", |
| "Sec-Fetch-Site": "cross-site", |
| "Sec-Fetch-User": "?1", |
| |
| |
| "Sec-Ch-Ua": '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', |
| "Sec-Ch-Ua-Mobile": "?0", |
| "Sec-Ch-Ua-Platform": '"Windows"', |
| "Sec-Ch-Ua-Arch": '"x86"', |
| "Sec-Ch-Ua-Bitness": '"64"', |
| "Sec-Ch-Ua-Full-Version-List": '"Google Chrome";v="131.0.6778.86", "Chromium";v="131.0.6778.86", "Not_A Brand";v="24.0.0.0"', |
| |
| |
| "Upgrade-Insecure-Requests": "1", |
| "DNT": "1", |
| "Cache-Control": "max-age=0", |
| "Priority": "u=0, i", |
| |
| |
| ...(req.headers.cookie && { "Cookie": req.headers.cookie }), |
| |
| |
| "CF-Connecting-IP": "8.8.8.8", |
| "X-Forwarded-For": "8.8.8.8", |
| "X-Real-IP": "8.8.8.8", |
| "X-Forwarded-Host": urlObj.hostname, |
| "X-Forwarded-Proto": "https", |
| |
| |
| "Device-Memory": "8", |
| "Viewport-Width": "1920", |
| "DPR": "1" |
| }, |
| responseType: "arraybuffer", |
| maxRedirects: 10, |
| validateStatus: () => true, |
| timeout: 30000, |
| decompress: true, |
| |
| |
| |
| |
| |
| httpAgent: false, |
| httpsAgent: false |
| }); |
|
|
| |
| const contentType = response.headers["content-type"] || "text/html; charset=utf-8"; |
| |
| |
| const headersToRemove = [ |
| "x-frame-options", |
| "content-security-policy", |
| "content-security-policy-report-only", |
| "x-content-security-policy", |
| "x-webkit-csp", |
| "strict-transport-security" |
| ]; |
| |
| |
| Object.keys(response.headers).forEach(key => { |
| if (!headersToRemove.includes(key.toLowerCase())) { |
| res.setHeader(key, response.headers[key]); |
| } |
| }); |
| |
| res.setHeader("Content-Type", contentType); |
| res.setHeader("Access-Control-Allow-Origin", "*"); |
| res.setHeader("Access-Control-Allow-Methods", "*"); |
| res.setHeader("Access-Control-Allow-Headers", "*"); |
| res.setHeader("X-Frame-Options", "ALLOWALL"); |
| res.setHeader("X-Content-Type-Options", "nosniff"); |
|
|
| |
| if (contentType.includes("text/html")) { |
| let html = response.data.toString("utf-8"); |
| |
| |
| const antiFrameBust = ` |
| <script> |
| (function() { |
| // Freeze top and parent |
| try { |
| Object.defineProperty(window, 'top', { |
| get: function() { return window.self; }, |
| set: function() {}, |
| configurable: false |
| }); |
| Object.defineProperty(window, 'parent', { |
| get: function() { return window.self; }, |
| set: function() {}, |
| configurable: false |
| }); |
| Object.defineProperty(window, 'frameElement', { |
| get: function() { return null; }, |
| set: function() {}, |
| configurable: false |
| }); |
| |
| // Override location checks |
| var originalLocation = window.location; |
| Object.defineProperty(window, 'location', { |
| get: function() { return originalLocation; }, |
| set: function(val) { |
| if (window.self === window.top) { |
| originalLocation = val; |
| } |
| } |
| }); |
| |
| // Disable common frame-busting patterns |
| window.onbeforeunload = null; |
| |
| // Intercept and block certain navigation attempts |
| var _confirm = window.confirm; |
| window.confirm = function() { return true; }; |
| |
| var _alert = window.alert; |
| window.alert = function() {}; |
| |
| } catch(e) { |
| console.log('Frame protection applied'); |
| } |
| })(); |
| </script> |
| `; |
| |
| |
| html = html.replace(/<!DOCTYPE/i, antiFrameBust + '<!DOCTYPE'); |
| html = html.replace(/<head>/i, `<head>${antiFrameBust}`); |
| html = html.replace(/<head\s/i, `<head>${antiFrameBust} `); |
| |
| |
| if (!/<head/i.test(html)) { |
| html = antiFrameBust + html; |
| } |
| |
| |
| html = html.replace( |
| /(src|href)=["'](https?:\/\/[^"']+)["']/gi, |
| (match, attr, url) => { |
| if (url.includes(urlObj.hostname)) { |
| return `${attr}="/proxy?url=${encodeURIComponent(url)}"`; |
| } |
| return match; |
| } |
| ); |
| |
| return res.send(html); |
| } |
|
|
| |
| res.send(response.data); |
|
|
| } catch (err) { |
| console.error("β Proxy error:", err.message); |
| console.error(" URL:", targetUrl); |
| console.error(" Status:", err.response?.status); |
| |
| res.status(err.response?.status || 500).send({ |
| error: "Proxy failed", |
| message: err.message, |
| url: targetUrl, |
| status: err.response?.status |
| }); |
| } |
| }); |
|
|
| |
| app.use("/fetch/*", async (req, res) => { |
| const targetUrl = req.params[0]; |
| |
| if (!targetUrl) return res.status(400).send("β No URL provided"); |
| |
| try { |
| const response = await axios.get(targetUrl, { |
| headers: { |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", |
| "Accept": "*/*", |
| "Accept-Language": "en-US,en;q=0.9", |
| "Accept-Encoding": "gzip, deflate, br", |
| "Referer": "https://www.808ball6.com/", |
| "Origin": "https://www.808ball6.com", |
| "Sec-Fetch-Dest": "empty", |
| "Sec-Fetch-Mode": "cors", |
| "Sec-Fetch-Site": "cross-site" |
| }, |
| responseType: "arraybuffer", |
| timeout: 30000, |
| validateStatus: () => true |
| }); |
| |
| res.setHeader("Content-Type", response.headers["content-type"] || "application/octet-stream"); |
| res.setHeader("Access-Control-Allow-Origin", "*"); |
| res.send(response.data); |
| |
| } catch (err) { |
| console.error("β Fetch error:", err.message); |
| res.status(500).send({ error: "Fetch failed", message: err.message }); |
| } |
| }); |
|
|
| |
| app.post("/proxy", async (req, res) => { |
| const { url } = req.query; |
| const body = req.body; |
| |
| if (!url) return res.status(400).send("β Missing ?url param"); |
| |
| const targetUrl = decodeURIComponent(url); |
| |
| try { |
| const response = await axios.post(targetUrl, body, { |
| headers: { |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", |
| "Content-Type": "application/json", |
| "Accept": "*/*", |
| "Referer": "https://www.808ball6.com/", |
| "Origin": "https://www.808ball6.com" |
| }, |
| validateStatus: () => true |
| }); |
| |
| res.status(response.status).json(response.data); |
| } catch (err) { |
| res.status(500).send({ error: "POST proxy failed", message: err.message }); |
| } |
| }); |
|
|
| const PORT = process.env.PORT || 7860; |
| app.listen(PORT, () => { |
| console.log(`\nπ Proxy Server Running`); |
| console.log(`π‘ Port: ${PORT}`); |
| console.log(`π Endpoints:`); |
| console.log(` β’ GET / (health check)`); |
| console.log(` β’ GET /proxy?url=<target>`); |
| console.log(` β’ GET /fetch/<target>`); |
| console.log(` β’ POST /proxy?url=<target>`); |
| }); |