somratpro commited on
Commit
cbd3c77
·
1 Parent(s): b50b822

feat: support custom proxy domains and wildcard mode

Browse files
Files changed (1) hide show
  1. outbound-fix.js +23 -10
outbound-fix.js CHANGED
@@ -14,13 +14,10 @@ if (PROXY_URL && !PROXY_URL.startsWith("http://") && !PROXY_URL.startsWith("http
14
  PROXY_URL = `https://${PROXY_URL}`;
15
  }
16
 
17
- const BLOCKED_DOMAINS = [
18
- "api.telegram.org",
19
- "discord.com",
20
- "discordapp.com",
21
- "gateway.discord.gg",
22
- "status.discord.com"
23
- ];
24
 
25
  if (PROXY_URL) {
26
  try {
@@ -50,10 +47,22 @@ if (PROXY_URL) {
50
  }
51
 
52
  // 2. Check if we should intercept (and prevent recursion)
53
- const isBlocked = BLOCKED_DOMAINS.some(domain => hostname === domain || hostname.endsWith("." + domain));
 
 
 
 
 
 
 
 
 
 
 
 
54
  const alreadyProxied = options._proxied || (headers && headers["x-target-host"]);
55
 
56
- if (isBlocked && !alreadyProxied) {
57
  console.log(`[outbound-fix] Redirecting ${hostname}${path} -> ${proxy.hostname}`);
58
 
59
  // 3. Create fresh options for the proxied request
@@ -92,7 +101,11 @@ if (PROXY_URL) {
92
  https.request = patch(originalHttpsRequest, true);
93
  http.request = patch(originalHttpRequest, false);
94
 
95
- console.log(`[outbound-fix] Transparent proxy active for: ${BLOCKED_DOMAINS.join(", ")}`);
 
 
 
 
96
  console.log(`[outbound-fix] Target proxy: ${proxy.hostname}`);
97
  } catch (e) {
98
  console.error(`[outbound-fix] Failed to initialize: ${e.message}`);
 
14
  PROXY_URL = `https://${PROXY_URL}`;
15
  }
16
 
17
+ // Allow user to define what to proxy. Use "*" to proxy everything except internal HF traffic.
18
+ const PROXY_DOMAINS = process.env.OUTBOUND_PROXY_DOMAINS || "api.telegram.org,discord.com,discordapp.com,gateway.discord.gg,status.discord.com";
19
+ const BLOCKED_DOMAINS = PROXY_DOMAINS.split(",").map(d => d.trim());
20
+ const PROXY_ALL = PROXY_DOMAINS === "*";
 
 
 
21
 
22
  if (PROXY_URL) {
23
  try {
 
47
  }
48
 
49
  // 2. Check if we should intercept (and prevent recursion)
50
+ const isInternal = hostname === "localhost" ||
51
+ hostname === "127.0.0.1" ||
52
+ hostname.endsWith(".hf.space") ||
53
+ hostname.endsWith(".huggingface.co") ||
54
+ hostname === "huggingface.co";
55
+
56
+ let shouldProxy = false;
57
+ if (PROXY_ALL) {
58
+ shouldProxy = !isInternal;
59
+ } else {
60
+ shouldProxy = BLOCKED_DOMAINS.some(domain => hostname === domain || hostname.endsWith("." + domain));
61
+ }
62
+
63
  const alreadyProxied = options._proxied || (headers && headers["x-target-host"]);
64
 
65
+ if (shouldProxy && !alreadyProxied) {
66
  console.log(`[outbound-fix] Redirecting ${hostname}${path} -> ${proxy.hostname}`);
67
 
68
  // 3. Create fresh options for the proxied request
 
101
  https.request = patch(originalHttpsRequest, true);
102
  http.request = patch(originalHttpRequest, false);
103
 
104
+ if (PROXY_ALL) {
105
+ console.log(`[outbound-fix] Transparent proxy active in WILDCARD mode (Proxying ALL except HF internal)`);
106
+ } else {
107
+ console.log(`[outbound-fix] Transparent proxy active for: ${BLOCKED_DOMAINS.join(", ")}`);
108
+ }
109
  console.log(`[outbound-fix] Target proxy: ${proxy.hostname}`);
110
  } catch (e) {
111
  console.error(`[outbound-fix] Failed to initialize: ${e.message}`);