Spaces:
Paused
Paused
feat: support custom proxy domains and wildcard mode
Browse files13 unmodified lines1415161718192021222324252623 unmodified lines5051525354555657585932 unmodified lines9293949596979813 unmodified linesPROXY_URL = `https://${PROXY_URL}`;}const BLOCKED_DOMAINS = ["api.telegram.org","discord.com","discordapp.com","gateway.discord.gg","status.discord.com"];if (PROXY_URL) {try {23 unmodified lines}// 2. Check if we should intercept (and prevent recursion)const isBlocked = BLOCKED_DOMAINS.some(domain => hostname === domain || hostname.endsWith("." + domain));const alreadyProxied = options._proxied || (headers && headers["x-target-host"]);if (isBlocked && !alreadyProxied) {console.log(`[outbound-fix] Redirecting ${hostname}${path} -> ${proxy.hostname}`);// 3. Create fresh options for the proxied request32 unmodified lineshttps.request = patch(originalHttpsRequest, true);http.request = patch(originalHttpRequest, false);console.log(`[outbound-fix] Transparent proxy active for: ${BLOCKED_DOMAINS.join(", ")}`);console.log(`[outbound-fix] Target proxy: ${proxy.hostname}`);} catch (e) {console.error(`[outbound-fix] Failed to initialize: ${e.message}`);13 unmodified lines1415161718192021222323 unmodified lines4748495051525354555657585960616263646566676832 unmodified lines10110210310410510610710810911011113 unmodified linesPROXY_URL = `https://${PROXY_URL}`;}// Allow user to define what to proxy. Use "*" to proxy everything except internal HF traffic.const PROXY_DOMAINS = process.env.OUTBOUND_PROXY_DOMAINS || "api.telegram.org,discord.com,discordapp.com,gateway.discord.gg,status.discord.com";const BLOCKED_DOMAINS = PROXY_DOMAINS.split(",").map(d => d.trim());const PROXY_ALL = PROXY_DOMAINS === "*";if (PROXY_URL) {try {23 unmodified lines}// 2. Check if we should intercept (and prevent recursion)const isInternal = hostname === "localhost" ||hostname === "127.0.0.1" ||hostname.endsWith(".hf.space") ||hostname.endsWith(".huggingface.co") ||hostname === "huggingface.co";let shouldProxy = false;if (PROXY_ALL) {shouldProxy = !isInternal;} else {shouldProxy = BLOCKED_DOMAINS.some(domain => hostname === domain || hostname.endsWith("." + domain));}const alreadyProxied = options._proxied || (headers && headers["x-target-host"]);if (shouldProxy && !alreadyProxied) {console.log(`[outbound-fix] Redirecting ${hostname}${path} -> ${proxy.hostname}`);// 3. Create fresh options for the proxied request32 unmodified lineshttps.request = patch(originalHttpsRequest, true);http.request = patch(originalHttpRequest, false);if (PROXY_ALL) {console.log(`[outbound-fix] Transparent proxy active in WILDCARD mode (Proxying ALL except HF internal)`);} else {console.log(`[outbound-fix] Transparent proxy active for: ${BLOCKED_DOMAINS.join(", ")}`);}console.log(`[outbound-fix] Target proxy: ${proxy.hostname}`);} catch (e) {console.error(`[outbound-fix] Failed to initialize: ${e.message}`);
outbound-fix.js+23-10