sub-bridge 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/tunnel/providers/cloudflare.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9D,qBAAa,wBAAyB,YAAW,cAAc;IAC7D,EAAE,SAAe;IACjB,IAAI,SAAe;IACnB,oBAAoB,UAAO;IAErB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAK/B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/tunnel/providers/cloudflare.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9D,qBAAa,wBAAyB,YAAW,cAAc;IAC7D,EAAE,SAAe;IACjB,IAAI,SAAe;IACnB,oBAAoB,UAAO;IAErB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAK/B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAkF3E"}
|
|
@@ -35,17 +35,57 @@ class CloudflareTunnelProvider {
|
|
|
35
35
|
await promises_1.default.writeFile(configPath, 'no-autoupdate: true\n');
|
|
36
36
|
// Use HTTP/2 protocol for more reliable connections
|
|
37
37
|
const tunnel = cloudflared_1.Tunnel.quick(`http://localhost:${localPort}`, { '--config': configPath, '--protocol': 'http2' });
|
|
38
|
-
// Wait for URL event
|
|
38
|
+
// Wait for URL event, then wait for connection to be established
|
|
39
39
|
const url = await new Promise((resolve, reject) => {
|
|
40
|
-
const timeout = setTimeout(() =>
|
|
40
|
+
const timeout = setTimeout(() => {
|
|
41
|
+
tunnel.stop();
|
|
42
|
+
reject(new Error('Tunnel timeout (60s)'));
|
|
43
|
+
}, 60000);
|
|
44
|
+
let tunnelUrl = null;
|
|
45
|
+
let lastError = null;
|
|
46
|
+
const checkReady = () => {
|
|
47
|
+
if (tunnelUrl) {
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
resolve(tunnelUrl);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Capture stderr for error messages (rate limiting, etc.)
|
|
53
|
+
tunnel.on('stderr', (data) => {
|
|
54
|
+
if (data.includes('ERR') || data.includes('error')) {
|
|
55
|
+
// Extract meaningful error message
|
|
56
|
+
if (data.includes('Too Many Requests') || data.includes('1015')) {
|
|
57
|
+
lastError = 'Cloudflare rate limit exceeded. Please wait a few minutes or use ngrok instead.';
|
|
58
|
+
}
|
|
59
|
+
else if (data.includes('failed to unmarshal')) {
|
|
60
|
+
lastError = data.split('\n').find(line => line.includes('failed'))?.trim() || data;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const errMatch = data.match(/ERR\s+(.+?)(?:\s+error=|$)/);
|
|
64
|
+
if (errMatch)
|
|
65
|
+
lastError = errMatch[1].trim();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
41
69
|
tunnel.once('url', (url) => {
|
|
42
|
-
|
|
43
|
-
|
|
70
|
+
tunnelUrl = url;
|
|
71
|
+
// Wait for connected event or timeout after 15s
|
|
72
|
+
const connectTimeout = setTimeout(checkReady, 15000);
|
|
73
|
+
tunnel.once('connected', () => {
|
|
74
|
+
clearTimeout(connectTimeout);
|
|
75
|
+
checkReady();
|
|
76
|
+
});
|
|
44
77
|
});
|
|
45
78
|
tunnel.once('error', (err) => {
|
|
46
79
|
clearTimeout(timeout);
|
|
47
80
|
reject(err);
|
|
48
81
|
});
|
|
82
|
+
// Handle process exit (e.g., rate limiting causes immediate exit)
|
|
83
|
+
tunnel.once('exit', (code) => {
|
|
84
|
+
if (code !== 0 && code !== null) {
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
reject(new Error(lastError || `Cloudflare tunnel exited with code ${code}`));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
49
89
|
});
|
|
50
90
|
return {
|
|
51
91
|
providerId: this.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../../src/tunnel/providers/cloudflare.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,6BAA6B;AAC7B,+EAA+E;;;;;;AAE/E,6CAAoC;AACpC,gEAAiC;AACjC,sDAAwB;AACxB,0DAA4B;AAG5B,MAAa,wBAAwB;IACnC,EAAE,GAAG,YAAY,CAAA;IACjB,IAAI,GAAG,YAAY,CAAA;IACnB,oBAAoB,GAAG,IAAI,CAAA;IAE3B,KAAK,CAAC,WAAW;QACf,uDAAuD;QACvD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,QAAiB;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACb,wDAAwD;YACxD,qFAAqF;YACrF,OAAO;gBACL,UAAU,EAAE,IAAI,CAAC,EAAE;gBACnB,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,QAAQ,EAAE;gBAC7E,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;aACf,CAAA;QACH,CAAC;QAED,iDAAiD;QACjD,MAAM,MAAM,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,mBAAI,CAAC,IAAI,CAAC,iBAAE,CAAC,MAAM,EAAE,EAAE,yBAAyB,CAAC,CAAC,CAAA;QAClF,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;QAClD,MAAM,k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AA;oBACrB,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,IAAI,sCAAsC,IAAI,EAAE,CAAC,CAAC,CAAA;gBAC9E,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,EAAE;YACnB,SAAS,EAAE,GAAG;YACd,IAAI,EAAE,GAAG,EAAE;gBACT,MAAM,CAAC,IAAI,EAAE,CAAA;gBACb,KAAK,kBAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YACtD,CAAC;SACF,CAAA;IACH,CAAC;CACF;AA5FD,4DA4FC"}
|
package/package.json
CHANGED
|
@@ -36,19 +36,59 @@ export class CloudflareTunnelProvider implements TunnelProvider {
|
|
|
36
36
|
// Use HTTP/2 protocol for more reliable connections
|
|
37
37
|
const tunnel = Tunnel.quick(`http://localhost:${localPort}`, { '--config': configPath, '--protocol': 'http2' })
|
|
38
38
|
|
|
39
|
-
// Wait for URL event
|
|
39
|
+
// Wait for URL event, then wait for connection to be established
|
|
40
40
|
const url = await new Promise<string>((resolve, reject) => {
|
|
41
|
-
const timeout = setTimeout(() =>
|
|
41
|
+
const timeout = setTimeout(() => {
|
|
42
|
+
tunnel.stop()
|
|
43
|
+
reject(new Error('Tunnel timeout (60s)'))
|
|
44
|
+
}, 60000)
|
|
45
|
+
let tunnelUrl: string | null = null
|
|
46
|
+
let lastError: string | null = null
|
|
47
|
+
|
|
48
|
+
const checkReady = () => {
|
|
49
|
+
if (tunnelUrl) {
|
|
50
|
+
clearTimeout(timeout)
|
|
51
|
+
resolve(tunnelUrl)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Capture stderr for error messages (rate limiting, etc.)
|
|
56
|
+
tunnel.on('stderr', (data: string) => {
|
|
57
|
+
if (data.includes('ERR') || data.includes('error')) {
|
|
58
|
+
// Extract meaningful error message
|
|
59
|
+
if (data.includes('Too Many Requests') || data.includes('1015')) {
|
|
60
|
+
lastError = 'Cloudflare rate limit exceeded. Please wait a few minutes or use ngrok instead.'
|
|
61
|
+
} else if (data.includes('failed to unmarshal')) {
|
|
62
|
+
lastError = data.split('\n').find(line => line.includes('failed'))?.trim() || data
|
|
63
|
+
} else {
|
|
64
|
+
const errMatch = data.match(/ERR\s+(.+?)(?:\s+error=|$)/)
|
|
65
|
+
if (errMatch) lastError = errMatch[1].trim()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})
|
|
42
69
|
|
|
43
70
|
tunnel.once('url', (url: string) => {
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
tunnelUrl = url
|
|
72
|
+
// Wait for connected event or timeout after 15s
|
|
73
|
+
const connectTimeout = setTimeout(checkReady, 15000)
|
|
74
|
+
tunnel.once('connected', () => {
|
|
75
|
+
clearTimeout(connectTimeout)
|
|
76
|
+
checkReady()
|
|
77
|
+
})
|
|
46
78
|
})
|
|
47
79
|
|
|
48
80
|
tunnel.once('error', (err: Error) => {
|
|
49
81
|
clearTimeout(timeout)
|
|
50
82
|
reject(err)
|
|
51
83
|
})
|
|
84
|
+
|
|
85
|
+
// Handle process exit (e.g., rate limiting causes immediate exit)
|
|
86
|
+
tunnel.once('exit', (code: number | null) => {
|
|
87
|
+
if (code !== 0 && code !== null) {
|
|
88
|
+
clearTimeout(timeout)
|
|
89
|
+
reject(new Error(lastError || `Cloudflare tunnel exited with code ${code}`))
|
|
90
|
+
}
|
|
91
|
+
})
|
|
52
92
|
})
|
|
53
93
|
|
|
54
94
|
return {
|