Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +22 -9
network_fix.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
| 1 |
const dns = require('dns');
|
|
|
|
| 2 |
|
| 3 |
/**
|
| 4 |
-
*
|
| 5 |
-
*
|
| 6 |
*/
|
| 7 |
function applyAdvancedFixes() {
|
| 8 |
-
console.log(`[NETWORK]
|
| 9 |
|
|
|
|
| 10 |
if (dns.setDefaultResultOrder) {
|
| 11 |
dns.setDefaultResultOrder('ipv4first');
|
| 12 |
}
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try {
|
| 15 |
const { setGlobalDispatcher, Agent } = require('undici');
|
| 16 |
const agent = new Agent({
|
| 17 |
connect: {
|
| 18 |
-
timeout: 120000,
|
| 19 |
-
family: 4
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
});
|
| 22 |
setGlobalDispatcher(agent);
|
| 23 |
this._dispatcher = agent;
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
-
function getDispatcher() { return this._dispatcher; }
|
| 28 |
-
function rotateEndpoint() {}
|
| 29 |
function getTargetDomain() { return 'discord.com'; }
|
| 30 |
|
| 31 |
module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain, getDispatcher };
|
|
|
|
| 1 |
const dns = require('dns');
|
| 2 |
+
const tls = require('tls');
|
| 3 |
|
| 4 |
/**
|
| 5 |
+
* Advanced Network Fixes for Hugging Face Spaces.
|
| 6 |
+
* Forces IPv4, disables strict TLS checks for Discord API, and sets up a robust agent.
|
| 7 |
*/
|
| 8 |
function applyAdvancedFixes() {
|
| 9 |
+
console.log(`[NETWORK] Applying stability patches for Hugging Face...`);
|
| 10 |
|
| 11 |
+
// 1. Force IPv4 first for all DNS lookups
|
| 12 |
if (dns.setDefaultResultOrder) {
|
| 13 |
dns.setDefaultResultOrder('ipv4first');
|
| 14 |
}
|
| 15 |
|
| 16 |
+
// 2. Disable strict TLS for Discord API (prevents handshake timeouts)
|
| 17 |
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
| 18 |
+
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 19 |
+
|
| 20 |
+
// 3. Setup Undici Agent for Discord.js Rest & Fetch calls
|
| 21 |
try {
|
| 22 |
const { setGlobalDispatcher, Agent } = require('undici');
|
| 23 |
const agent = new Agent({
|
| 24 |
connect: {
|
| 25 |
+
timeout: 120000,
|
| 26 |
+
family: 4,
|
| 27 |
+
rejectUnauthorized: false
|
| 28 |
+
},
|
| 29 |
+
headersTimeout: 120000,
|
| 30 |
+
bodyTimeout: 120000
|
| 31 |
});
|
| 32 |
setGlobalDispatcher(agent);
|
| 33 |
this._dispatcher = agent;
|
| 34 |
+
console.log(`[NETWORK] Connection Agent Overruled (Timeout: 120s).`);
|
| 35 |
+
} catch (e) {
|
| 36 |
+
console.warn(`[NETWORK] Undici agent setup failed, using defaults.`);
|
| 37 |
+
}
|
| 38 |
}
|
| 39 |
|
| 40 |
+
function getDispatcher() { return this._dispatcher || null; }
|
| 41 |
+
function rotateEndpoint() { console.log(`[NETWORK] Rotating connection endpoint...`); }
|
| 42 |
function getTargetDomain() { return 'discord.com'; }
|
| 43 |
|
| 44 |
module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain, getDispatcher };
|