Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +7 -2
network_fix.js
CHANGED
|
@@ -25,14 +25,19 @@ function applyAdvancedFixes() {
|
|
| 25 |
const patchAgent = (AgentClass) => {
|
| 26 |
const _old = AgentClass.prototype.createConnection;
|
| 27 |
AgentClass.prototype.createConnection = function(options, callback) {
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
options.hostname = target_domain;
|
| 30 |
options.servername = target_domain;
|
| 31 |
if (!options.headers) options.headers = {};
|
| 32 |
options.headers['User-Agent'] = UA;
|
| 33 |
}
|
|
|
|
| 34 |
// Force IPv4 if possible by setting family to 4
|
| 35 |
-
if (
|
| 36 |
options.family = 4;
|
| 37 |
}
|
| 38 |
return _old.call(this, options, callback);
|
|
|
|
| 25 |
const patchAgent = (AgentClass) => {
|
| 26 |
const _old = AgentClass.prototype.createConnection;
|
| 27 |
AgentClass.prototype.createConnection = function(options, callback) {
|
| 28 |
+
const isDiscord = options.hostname && options.hostname.includes('discord');
|
| 29 |
+
const isGateway = options.hostname && options.hostname.includes('gateway');
|
| 30 |
+
|
| 31 |
+
if (isDiscord && !isGateway && !options.hostname.includes(target_domain)) {
|
| 32 |
+
// console.log(`[NetworkFix] Redirecting ${options.hostname} -> ${target_domain}`);
|
| 33 |
options.hostname = target_domain;
|
| 34 |
options.servername = target_domain;
|
| 35 |
if (!options.headers) options.headers = {};
|
| 36 |
options.headers['User-Agent'] = UA;
|
| 37 |
}
|
| 38 |
+
|
| 39 |
// Force IPv4 if possible by setting family to 4
|
| 40 |
+
if (isDiscord) {
|
| 41 |
options.family = 4;
|
| 42 |
}
|
| 43 |
return _old.call(this, options, callback);
|