@ngrok/ngrok 0.6.0 → 0.7.1
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.
- package/CHANGELOG.md +9 -0
- package/Cargo.toml +5 -2
- package/README.md +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/NgrokHttpTunnelBuilder.html +55 -21
- package/docs/classes/NgrokLabeledTunnelBuilder.html +38 -4
- package/docs/classes/NgrokSession.html +8 -8
- package/docs/classes/NgrokSessionBuilder.html +16 -16
- package/docs/classes/NgrokTcpTunnelBuilder.html +42 -8
- package/docs/classes/NgrokTlsTunnelBuilder.html +44 -10
- package/docs/classes/NgrokTunnel.html +21 -9
- package/docs/classes/UpdateRequest.html +3 -3
- package/docs/functions/authtoken.html +1 -1
- package/docs/functions/connect.html +1 -1
- package/docs/functions/consoleLog.html +1 -1
- package/docs/functions/disconnect.html +1 -1
- package/docs/functions/getTunnel.html +1 -1
- package/docs/functions/getTunnelByUrl.html +1 -1
- package/docs/functions/kill.html +1 -1
- package/docs/functions/listen.html +1 -1
- package/docs/functions/listenable.html +1 -1
- package/docs/functions/loggingCallback.html +1 -1
- package/docs/functions/tunnels.html +1 -1
- package/docs/interfaces/Config.html +53 -53
- package/examples/ngrok-connect-full.js +1 -1
- package/examples/ngrok-labeled.js +1 -1
- package/index.d.ts +19 -1
- package/index.js +19 -3
- package/package.json +14 -14
- package/src/config.rs +1 -1
- package/src/connect.rs +7 -4
- package/src/http.rs +20 -22
- package/src/lib.rs +1 -1
- package/src/session.rs +45 -45
- package/src/tcp.rs +1 -1
- package/src/tls.rs +3 -5
- package/src/tunnel.rs +118 -31
- package/src/tunnel_builder.rs +33 -6
- package/trailer.js +18 -2
package/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
export interface Config {
|
|
12
12
|
/**
|
|
13
13
|
* Port, network address, or named pipe. Defaults to 80.
|
|
14
|
-
* Examples: "80", "localhost:8080", "
|
|
14
|
+
* Examples: "80", "localhost:8080", "unix:/tmp/my.sock", "pipe://./my-pipe"
|
|
15
15
|
*/
|
|
16
16
|
addr?: number|string
|
|
17
17
|
auth?: string|Array<string>
|
|
@@ -395,6 +395,8 @@ export class NgrokTunnel {
|
|
|
395
395
|
* On Windows, addr can be a named pipe, e.e. "\\\\.\\pipe\\an_ngrok_pipe
|
|
396
396
|
*/
|
|
397
397
|
forward(addr: string): Promise<void>
|
|
398
|
+
/** Wait for the forwarding task to exit. */
|
|
399
|
+
join(): Promise<void>
|
|
398
400
|
/**
|
|
399
401
|
* Close the tunnel.
|
|
400
402
|
*
|
|
@@ -461,6 +463,10 @@ export class NgrokHttpTunnelBuilder {
|
|
|
461
463
|
metadata(metadata: string): this
|
|
462
464
|
/** Begin listening for new connections on this tunnel. */
|
|
463
465
|
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
466
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given url. */
|
|
467
|
+
listenAndForward(toUrl: string): Promise<NgrokTunnel>
|
|
468
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given server. */
|
|
469
|
+
listenAndServe(server: any): Promise<NgrokTunnel>
|
|
464
470
|
/**
|
|
465
471
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
466
472
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -491,6 +497,10 @@ export class NgrokTcpTunnelBuilder {
|
|
|
491
497
|
metadata(metadata: string): this
|
|
492
498
|
/** Begin listening for new connections on this tunnel. */
|
|
493
499
|
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
500
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given url. */
|
|
501
|
+
listenAndForward(toUrl: string): Promise<NgrokTunnel>
|
|
502
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given server. */
|
|
503
|
+
listenAndServe(server: any): Promise<NgrokTunnel>
|
|
494
504
|
/**
|
|
495
505
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
496
506
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -525,6 +535,10 @@ export class NgrokTlsTunnelBuilder {
|
|
|
525
535
|
metadata(metadata: string): this
|
|
526
536
|
/** Begin listening for new connections on this tunnel. */
|
|
527
537
|
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
538
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given url. */
|
|
539
|
+
listenAndForward(toUrl: string): Promise<NgrokTunnel>
|
|
540
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given server. */
|
|
541
|
+
listenAndServe(server: any): Promise<NgrokTunnel>
|
|
528
542
|
/**
|
|
529
543
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
530
544
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -553,6 +567,10 @@ export class NgrokLabeledTunnelBuilder {
|
|
|
553
567
|
metadata(metadata: string): this
|
|
554
568
|
/** Begin listening for new connections on this tunnel. */
|
|
555
569
|
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
570
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given url. */
|
|
571
|
+
listenAndForward(toUrl: string): Promise<NgrokTunnel>
|
|
572
|
+
/** Begin listening for new connections on this tunnel and forwarding them to the given server. */
|
|
573
|
+
listenAndServe(server: any): Promise<NgrokTunnel>
|
|
556
574
|
/** Add a label, value pair for this tunnel. */
|
|
557
575
|
label(label: string, value: string): this
|
|
558
576
|
}
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function isMusl() {
|
|
|
17
17
|
// For Node 10
|
|
18
18
|
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
19
|
try {
|
|
20
|
-
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
21
|
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
22
|
} catch (e) {
|
|
23
23
|
return true
|
|
@@ -294,6 +294,11 @@ NgrokTcpTunnelBuilder.prototype.listen = ngrokBind;
|
|
|
294
294
|
NgrokTlsTunnelBuilder.prototype.listen = ngrokBind;
|
|
295
295
|
NgrokLabeledTunnelBuilder.prototype.listen = ngrokBind;
|
|
296
296
|
|
|
297
|
+
NgrokHttpTunnelBuilder.prototype.listenAndServe = listenAndServe;
|
|
298
|
+
NgrokTcpTunnelBuilder.prototype.listenAndServe = listenAndServe;
|
|
299
|
+
NgrokTlsTunnelBuilder.prototype.listenAndServe = listenAndServe;
|
|
300
|
+
NgrokLabeledTunnelBuilder.prototype.listenAndServe = listenAndServe;
|
|
301
|
+
|
|
297
302
|
// Wrap session connect to fill in exception's errorCode
|
|
298
303
|
async function ngrokSessionConnect() {
|
|
299
304
|
try {
|
|
@@ -322,6 +327,13 @@ async function ngrokBind(bind) {
|
|
|
322
327
|
}
|
|
323
328
|
}
|
|
324
329
|
|
|
330
|
+
/// Begin listening for new connections on this tunnel and forwarding them to the given server.
|
|
331
|
+
async function listenAndServe(server) {
|
|
332
|
+
const tunnel = await this._listen();
|
|
333
|
+
tunnel.socket = await ngrokListen(server, tunnel);
|
|
334
|
+
return tunnel;
|
|
335
|
+
}
|
|
336
|
+
|
|
325
337
|
function populateErrorCode(err) {
|
|
326
338
|
if (err.message) {
|
|
327
339
|
const regex = /error_code: (ERR_NGROK_\d+)$/;
|
|
@@ -476,8 +488,12 @@ async function ngrokLinkPipe(tunnel, server) {
|
|
|
476
488
|
console.debug("Cannot change permissions of file: " + filename);
|
|
477
489
|
}
|
|
478
490
|
// forward tunnel
|
|
479
|
-
|
|
480
|
-
|
|
491
|
+
var addr = "unix:" + filename;
|
|
492
|
+
if (platform == "win32") {
|
|
493
|
+
// convert pipe path to url
|
|
494
|
+
addr = "pipe:" + filename.replace("\\\\.\\pipe\\", "//./");
|
|
495
|
+
}
|
|
496
|
+
tunnel.forward(addr);
|
|
481
497
|
socket.path = filename; // surface to caller
|
|
482
498
|
|
|
483
499
|
return socket;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/ngrok",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -55,18 +55,18 @@
|
|
|
55
55
|
"description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
|
|
56
56
|
"repository": "https://github.com/ngrok/ngrok-nodejs",
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"@ngrok/ngrok-win32-x64-msvc": "0.
|
|
59
|
-
"@ngrok/ngrok-darwin-x64": "0.
|
|
60
|
-
"@ngrok/ngrok-linux-x64-gnu": "0.
|
|
61
|
-
"@ngrok/ngrok-darwin-arm64": "0.
|
|
62
|
-
"@ngrok/ngrok-android-arm64": "0.
|
|
63
|
-
"@ngrok/ngrok-linux-arm64-gnu": "0.
|
|
64
|
-
"@ngrok/ngrok-linux-arm64-musl": "0.
|
|
65
|
-
"@ngrok/ngrok-linux-arm-gnueabihf": "0.
|
|
66
|
-
"@ngrok/ngrok-linux-x64-musl": "0.
|
|
67
|
-
"@ngrok/ngrok-freebsd-x64": "0.
|
|
68
|
-
"@ngrok/ngrok-win32-ia32-msvc": "0.
|
|
69
|
-
"@ngrok/ngrok-android-arm-eabi": "0.
|
|
70
|
-
"@ngrok/ngrok-darwin-universal": "0.
|
|
58
|
+
"@ngrok/ngrok-win32-x64-msvc": "0.7.1",
|
|
59
|
+
"@ngrok/ngrok-darwin-x64": "0.7.1",
|
|
60
|
+
"@ngrok/ngrok-linux-x64-gnu": "0.7.1",
|
|
61
|
+
"@ngrok/ngrok-darwin-arm64": "0.7.1",
|
|
62
|
+
"@ngrok/ngrok-android-arm64": "0.7.1",
|
|
63
|
+
"@ngrok/ngrok-linux-arm64-gnu": "0.7.1",
|
|
64
|
+
"@ngrok/ngrok-linux-arm64-musl": "0.7.1",
|
|
65
|
+
"@ngrok/ngrok-linux-arm-gnueabihf": "0.7.1",
|
|
66
|
+
"@ngrok/ngrok-linux-x64-musl": "0.7.1",
|
|
67
|
+
"@ngrok/ngrok-freebsd-x64": "0.7.1",
|
|
68
|
+
"@ngrok/ngrok-win32-ia32-msvc": "0.7.1",
|
|
69
|
+
"@ngrok/ngrok-android-arm-eabi": "0.7.1",
|
|
70
|
+
"@ngrok/ngrok-darwin-universal": "0.7.1"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/config.rs
CHANGED
|
@@ -7,7 +7,7 @@ use napi_derive::napi;
|
|
|
7
7
|
#[derive(Default)]
|
|
8
8
|
pub struct Config {
|
|
9
9
|
/// Port, network address, or named pipe. Defaults to 80.
|
|
10
|
-
/// Examples: "80", "localhost:8080", "
|
|
10
|
+
/// Examples: "80", "localhost:8080", "unix:/tmp/my.sock", "pipe://./my-pipe"
|
|
11
11
|
#[napi(ts_type = "number|string")]
|
|
12
12
|
pub addr: Option<String>,
|
|
13
13
|
// Synonym for basic_auth
|
package/src/connect.rs
CHANGED
|
@@ -16,6 +16,7 @@ use crate::{
|
|
|
16
16
|
NgrokSessionBuilder,
|
|
17
17
|
},
|
|
18
18
|
tunnel,
|
|
19
|
+
tunnel::TCP_PREFIX,
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
lazy_static! {
|
|
@@ -23,8 +24,6 @@ lazy_static! {
|
|
|
23
24
|
pub(crate) static ref SESSION: Mutex<Option<NgrokSession>> = Mutex::new(None);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
pub(crate) const PIPE_PREFIX: &str = "pipe:";
|
|
27
|
-
|
|
28
27
|
/// Single string configuration
|
|
29
28
|
macro_rules! plumb {
|
|
30
29
|
($builder:tt, $config:tt, $name:tt) => {
|
|
@@ -260,7 +259,11 @@ fn set_defaults(config: &mut Config) {
|
|
|
260
259
|
}
|
|
261
260
|
if config.addr.is_none() {
|
|
262
261
|
if let Some(port) = &config.port {
|
|
263
|
-
config.
|
|
262
|
+
if let Some(host) = &config.host {
|
|
263
|
+
config.addr.replace(format!("{TCP_PREFIX}{host}:{port}"));
|
|
264
|
+
} else {
|
|
265
|
+
config.addr.replace(format!("{TCP_PREFIX}localhost:{port}"));
|
|
266
|
+
}
|
|
264
267
|
} else if let Some(host) = &config.host {
|
|
265
268
|
config.addr.replace(host.clone());
|
|
266
269
|
} else {
|
|
@@ -270,7 +273,7 @@ fn set_defaults(config: &mut Config) {
|
|
|
270
273
|
if let Some(addr) = &config.addr {
|
|
271
274
|
if addr.parse::<i32>().is_ok() {
|
|
272
275
|
// the string is a number, interpret it as a port
|
|
273
|
-
config.addr.replace(format!("localhost:{addr}"));
|
|
276
|
+
config.addr.replace(format!("{TCP_PREFIX}localhost:{addr}"));
|
|
274
277
|
}
|
|
275
278
|
}
|
|
276
279
|
}
|
package/src/http.rs
CHANGED
|
@@ -19,7 +19,7 @@ impl NgrokHttpTunnelBuilder {
|
|
|
19
19
|
#[napi]
|
|
20
20
|
pub fn scheme(&mut self, scheme: String) -> &Self {
|
|
21
21
|
let mut builder = self.tunnel_builder.lock();
|
|
22
|
-
|
|
22
|
+
builder.scheme(
|
|
23
23
|
Scheme::from_str(scheme.as_str())
|
|
24
24
|
.unwrap_or_else(|_| panic!("Unknown scheme: {scheme:?}")),
|
|
25
25
|
);
|
|
@@ -29,30 +29,28 @@ impl NgrokHttpTunnelBuilder {
|
|
|
29
29
|
#[napi]
|
|
30
30
|
pub fn domain(&mut self, domain: String) -> &Self {
|
|
31
31
|
let mut builder = self.tunnel_builder.lock();
|
|
32
|
-
|
|
32
|
+
builder.domain(domain);
|
|
33
33
|
self
|
|
34
34
|
}
|
|
35
35
|
/// Certificates to use for client authentication at the ngrok edge.
|
|
36
36
|
#[napi]
|
|
37
37
|
pub fn mutual_tlsca(&mut self, mutual_tlsca: Uint8Array) -> &Self {
|
|
38
38
|
let mut builder = self.tunnel_builder.lock();
|
|
39
|
-
|
|
40
|
-
.clone()
|
|
41
|
-
.mutual_tlsca(Bytes::from(mutual_tlsca.to_vec()));
|
|
39
|
+
builder.mutual_tlsca(Bytes::from(mutual_tlsca.to_vec()));
|
|
42
40
|
self
|
|
43
41
|
}
|
|
44
42
|
/// Enable gzip compression for HTTP responses.
|
|
45
43
|
#[napi]
|
|
46
44
|
pub fn compression(&mut self) -> &Self {
|
|
47
45
|
let mut builder = self.tunnel_builder.lock();
|
|
48
|
-
|
|
46
|
+
builder.compression();
|
|
49
47
|
self
|
|
50
48
|
}
|
|
51
49
|
/// Convert incoming websocket connections to TCP-like streams.
|
|
52
50
|
#[napi]
|
|
53
51
|
pub fn websocket_tcp_conversion(&mut self) -> &Self {
|
|
54
52
|
let mut builder = self.tunnel_builder.lock();
|
|
55
|
-
|
|
53
|
+
builder.websocket_tcp_conversion();
|
|
56
54
|
self
|
|
57
55
|
}
|
|
58
56
|
/// Reject requests when 5XX responses exceed this ratio.
|
|
@@ -60,7 +58,7 @@ impl NgrokHttpTunnelBuilder {
|
|
|
60
58
|
#[napi]
|
|
61
59
|
pub fn circuit_breaker(&mut self, circuit_breaker: f64) -> &Self {
|
|
62
60
|
let mut builder = self.tunnel_builder.lock();
|
|
63
|
-
|
|
61
|
+
builder.circuit_breaker(circuit_breaker);
|
|
64
62
|
self
|
|
65
63
|
}
|
|
66
64
|
|
|
@@ -68,28 +66,28 @@ impl NgrokHttpTunnelBuilder {
|
|
|
68
66
|
#[napi]
|
|
69
67
|
pub fn request_header(&mut self, name: String, value: String) -> &Self {
|
|
70
68
|
let mut builder = self.tunnel_builder.lock();
|
|
71
|
-
|
|
69
|
+
builder.request_header(name, value);
|
|
72
70
|
self
|
|
73
71
|
}
|
|
74
72
|
/// response_header adds a header to all responses coming from this edge.
|
|
75
73
|
#[napi]
|
|
76
74
|
pub fn response_header(&mut self, name: String, value: String) -> &Self {
|
|
77
75
|
let mut builder = self.tunnel_builder.lock();
|
|
78
|
-
|
|
76
|
+
builder.response_header(name, value);
|
|
79
77
|
self
|
|
80
78
|
}
|
|
81
79
|
/// remove_request_header removes a header from requests to this edge.
|
|
82
80
|
#[napi]
|
|
83
81
|
pub fn remove_request_header(&mut self, name: String) -> &Self {
|
|
84
82
|
let mut builder = self.tunnel_builder.lock();
|
|
85
|
-
|
|
83
|
+
builder.remove_request_header(name);
|
|
86
84
|
self
|
|
87
85
|
}
|
|
88
86
|
/// remove_response_header removes a header from responses from this edge.
|
|
89
87
|
#[napi]
|
|
90
88
|
pub fn remove_response_header(&mut self, name: String) -> &Self {
|
|
91
89
|
let mut builder = self.tunnel_builder.lock();
|
|
92
|
-
|
|
90
|
+
builder.remove_response_header(name);
|
|
93
91
|
self
|
|
94
92
|
}
|
|
95
93
|
|
|
@@ -98,7 +96,7 @@ impl NgrokHttpTunnelBuilder {
|
|
|
98
96
|
#[napi]
|
|
99
97
|
pub fn basic_auth(&mut self, username: String, password: String) -> &Self {
|
|
100
98
|
let mut builder = self.tunnel_builder.lock();
|
|
101
|
-
|
|
99
|
+
builder.basic_auth(username, password);
|
|
102
100
|
self
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -116,22 +114,22 @@ impl NgrokHttpTunnelBuilder {
|
|
|
116
114
|
let mut oauth = OauthOptions::new(provider);
|
|
117
115
|
if let Some(allow_emails) = allow_emails {
|
|
118
116
|
allow_emails.iter().for_each(|v| {
|
|
119
|
-
oauth
|
|
117
|
+
oauth.allow_email(v);
|
|
120
118
|
});
|
|
121
119
|
}
|
|
122
120
|
if let Some(allow_domains) = allow_domains {
|
|
123
121
|
allow_domains.iter().for_each(|v| {
|
|
124
|
-
oauth
|
|
122
|
+
oauth.allow_domain(v);
|
|
125
123
|
});
|
|
126
124
|
}
|
|
127
125
|
if let Some(scopes) = scopes {
|
|
128
126
|
scopes.iter().for_each(|v| {
|
|
129
|
-
oauth
|
|
127
|
+
oauth.scope(v);
|
|
130
128
|
});
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
let mut builder = self.tunnel_builder.lock();
|
|
134
|
-
|
|
132
|
+
builder.oauth(oauth);
|
|
135
133
|
self
|
|
136
134
|
}
|
|
137
135
|
|
|
@@ -150,22 +148,22 @@ impl NgrokHttpTunnelBuilder {
|
|
|
150
148
|
let mut oidc = OidcOptions::new(issuer_url, client_id, client_secret);
|
|
151
149
|
if let Some(allow_emails) = allow_emails {
|
|
152
150
|
allow_emails.iter().for_each(|v| {
|
|
153
|
-
oidc
|
|
151
|
+
oidc.allow_email(v);
|
|
154
152
|
});
|
|
155
153
|
}
|
|
156
154
|
if let Some(allow_domains) = allow_domains {
|
|
157
155
|
allow_domains.iter().for_each(|v| {
|
|
158
|
-
oidc
|
|
156
|
+
oidc.allow_domain(v);
|
|
159
157
|
});
|
|
160
158
|
}
|
|
161
159
|
if let Some(scopes) = scopes {
|
|
162
160
|
scopes.iter().for_each(|v| {
|
|
163
|
-
oidc
|
|
161
|
+
oidc.scope(v);
|
|
164
162
|
});
|
|
165
163
|
}
|
|
166
164
|
|
|
167
165
|
let mut builder = self.tunnel_builder.lock();
|
|
168
|
-
|
|
166
|
+
builder.oidc(oidc);
|
|
169
167
|
self
|
|
170
168
|
}
|
|
171
169
|
|
|
@@ -174,7 +172,7 @@ impl NgrokHttpTunnelBuilder {
|
|
|
174
172
|
#[napi]
|
|
175
173
|
pub fn webhook_verification(&mut self, provider: String, secret: String) -> &Self {
|
|
176
174
|
let mut builder = self.tunnel_builder.lock();
|
|
177
|
-
|
|
175
|
+
builder.webhook_verification(provider, secret);
|
|
178
176
|
self
|
|
179
177
|
}
|
|
180
178
|
}
|
package/src/lib.rs
CHANGED
package/src/session.rs
CHANGED
|
@@ -34,6 +34,7 @@ use tracing::{
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
use crate::{
|
|
37
|
+
napi_err,
|
|
37
38
|
napi_ngrok_err,
|
|
38
39
|
tunnel::{
|
|
39
40
|
remove_global_tunnel,
|
|
@@ -88,11 +89,11 @@ impl NgrokSessionBuilder {
|
|
|
88
89
|
#[napi(constructor)]
|
|
89
90
|
pub fn new() -> Self {
|
|
90
91
|
NgrokSessionBuilder {
|
|
91
|
-
raw_builder: Arc::new(SyncMutex::new(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
))
|
|
92
|
+
raw_builder: Arc::new(SyncMutex::new(
|
|
93
|
+
Session::builder()
|
|
94
|
+
.client_info(CLIENT_TYPE, VERSION, None::<String>)
|
|
95
|
+
.clone(),
|
|
96
|
+
)),
|
|
96
97
|
..Default::default()
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -109,7 +110,7 @@ impl NgrokSessionBuilder {
|
|
|
109
110
|
#[napi]
|
|
110
111
|
pub fn authtoken(&mut self, authtoken: String) -> &Self {
|
|
111
112
|
let mut builder = self.raw_builder.lock();
|
|
112
|
-
|
|
113
|
+
builder.authtoken(authtoken);
|
|
113
114
|
self.auth_token_set = true;
|
|
114
115
|
self
|
|
115
116
|
}
|
|
@@ -119,7 +120,7 @@ impl NgrokSessionBuilder {
|
|
|
119
120
|
#[napi]
|
|
120
121
|
pub fn authtoken_from_env(&mut self) -> &Self {
|
|
121
122
|
let mut builder = self.raw_builder.lock();
|
|
122
|
-
|
|
123
|
+
builder.authtoken_from_env();
|
|
123
124
|
self.auth_token_set = true;
|
|
124
125
|
self
|
|
125
126
|
}
|
|
@@ -141,7 +142,7 @@ impl NgrokSessionBuilder {
|
|
|
141
142
|
comments: Option<String>,
|
|
142
143
|
) -> &Self {
|
|
143
144
|
let mut builder = self.raw_builder.lock();
|
|
144
|
-
|
|
145
|
+
builder.client_info(client_type, version, comments);
|
|
145
146
|
self
|
|
146
147
|
}
|
|
147
148
|
|
|
@@ -153,12 +154,12 @@ impl NgrokSessionBuilder {
|
|
|
153
154
|
///
|
|
154
155
|
/// [heartbeat_interval parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_interval
|
|
155
156
|
#[napi]
|
|
156
|
-
pub fn heartbeat_interval(&mut self, heartbeat_interval: u32) ->
|
|
157
|
+
pub fn heartbeat_interval(&mut self, heartbeat_interval: u32) -> Result<&Self> {
|
|
157
158
|
let mut builder = self.raw_builder.lock();
|
|
158
|
-
|
|
159
|
-
.
|
|
160
|
-
.
|
|
161
|
-
self
|
|
159
|
+
builder
|
|
160
|
+
.heartbeat_interval(Duration::new(heartbeat_interval.into(), 0))
|
|
161
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
162
|
+
Ok(self)
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
/// Configures the duration to wait for a response to a heartbeat before
|
|
@@ -169,12 +170,12 @@ impl NgrokSessionBuilder {
|
|
|
169
170
|
///
|
|
170
171
|
/// [heartbeat_tolerance parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_tolerance
|
|
171
172
|
#[napi]
|
|
172
|
-
pub fn heartbeat_tolerance(&mut self, heartbeat_tolerance: u32) ->
|
|
173
|
+
pub fn heartbeat_tolerance(&mut self, heartbeat_tolerance: u32) -> Result<&Self> {
|
|
173
174
|
let mut builder = self.raw_builder.lock();
|
|
174
|
-
|
|
175
|
-
.
|
|
176
|
-
.
|
|
177
|
-
self
|
|
175
|
+
builder
|
|
176
|
+
.heartbeat_tolerance(Duration::new(heartbeat_tolerance.into(), 0))
|
|
177
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
178
|
+
Ok(self)
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
/// Configures the opaque, machine-readable metadata string for this session.
|
|
@@ -188,7 +189,7 @@ impl NgrokSessionBuilder {
|
|
|
188
189
|
#[napi]
|
|
189
190
|
pub fn metadata(&mut self, metadata: String) -> &Self {
|
|
190
191
|
let mut builder = self.raw_builder.lock();
|
|
191
|
-
|
|
192
|
+
builder.metadata(metadata);
|
|
192
193
|
self
|
|
193
194
|
}
|
|
194
195
|
|
|
@@ -199,10 +200,12 @@ impl NgrokSessionBuilder {
|
|
|
199
200
|
///
|
|
200
201
|
/// [server_addr parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#server_addr
|
|
201
202
|
#[napi]
|
|
202
|
-
pub fn server_addr(&mut self, addr: String) ->
|
|
203
|
+
pub fn server_addr(&mut self, addr: String) -> Result<&Self> {
|
|
203
204
|
let mut builder = self.raw_builder.lock();
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
builder
|
|
206
|
+
.server_addr(addr)
|
|
207
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
208
|
+
Ok(self)
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
/// Configures the TLS certificate used to connect to the ngrok service while
|
|
@@ -217,7 +220,7 @@ impl NgrokSessionBuilder {
|
|
|
217
220
|
#[napi]
|
|
218
221
|
pub fn ca_cert(&mut self, cert_bytes: Uint8Array) -> &Self {
|
|
219
222
|
let mut builder = self.raw_builder.lock();
|
|
220
|
-
|
|
223
|
+
builder.ca_cert(Bytes::from(cert_bytes.to_vec()));
|
|
221
224
|
self
|
|
222
225
|
}
|
|
223
226
|
|
|
@@ -249,8 +252,11 @@ impl NgrokSessionBuilder {
|
|
|
249
252
|
// clone for move to connector function
|
|
250
253
|
let connect_handler = self.connect_handler.clone();
|
|
251
254
|
let disconnect_handler = self.disconnect_handler.clone();
|
|
252
|
-
|
|
253
|
-
move |
|
|
255
|
+
builder.connector(
|
|
256
|
+
move |host: String,
|
|
257
|
+
port: u16,
|
|
258
|
+
tls_config: Arc<ClientConfig>,
|
|
259
|
+
err: Option<AcceptError>| {
|
|
254
260
|
// clone for async move out of environment
|
|
255
261
|
let conn_tsfn = connect_handler.clone();
|
|
256
262
|
let disconn_tsfn = disconnect_handler.clone();
|
|
@@ -263,21 +269,21 @@ impl NgrokSessionBuilder {
|
|
|
263
269
|
.clone()
|
|
264
270
|
.lock()
|
|
265
271
|
.await
|
|
266
|
-
.call_async(vec![
|
|
272
|
+
.call_async(vec![format!("{host}:{port}"), err.to_string()])
|
|
267
273
|
.await
|
|
268
274
|
.map_err(|_e| ConnectError::Canceled)?;
|
|
269
275
|
|
|
270
276
|
if let Some(reconnect) = resp {
|
|
271
277
|
if !reconnect {
|
|
272
|
-
info!("Aborting connection to {
|
|
273
|
-
println!("Aborting connection to {
|
|
278
|
+
info!("Aborting connection to {host}:{port}");
|
|
279
|
+
println!("Aborting connection to {host}:{port}"); // still shown if this takes down the process
|
|
274
280
|
return Err(ConnectError::Canceled);
|
|
275
281
|
}
|
|
276
282
|
}
|
|
277
283
|
};
|
|
278
284
|
}
|
|
279
285
|
// call the upstream connector
|
|
280
|
-
let res = default_connect(
|
|
286
|
+
let res = default_connect(host, port, tls_config, err).await;
|
|
281
287
|
|
|
282
288
|
// call connect handler
|
|
283
289
|
if let Some(handler) = conn_tsfn {
|
|
@@ -317,9 +323,7 @@ impl NgrokSessionBuilder {
|
|
|
317
323
|
let tsfn = create_tsfn(env, handler);
|
|
318
324
|
// register stop handler
|
|
319
325
|
let mut builder = self.raw_builder.lock();
|
|
320
|
-
|
|
321
|
-
.clone()
|
|
322
|
-
.handle_stop_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
326
|
+
builder.handle_stop_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
323
327
|
self
|
|
324
328
|
}
|
|
325
329
|
|
|
@@ -340,9 +344,7 @@ impl NgrokSessionBuilder {
|
|
|
340
344
|
let tsfn = create_tsfn(env, handler);
|
|
341
345
|
// register restart handler
|
|
342
346
|
let mut builder = self.raw_builder.lock();
|
|
343
|
-
|
|
344
|
-
.clone()
|
|
345
|
-
.handle_restart_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
347
|
+
builder.handle_restart_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
346
348
|
self
|
|
347
349
|
}
|
|
348
350
|
|
|
@@ -363,7 +365,7 @@ impl NgrokSessionBuilder {
|
|
|
363
365
|
let tsfn = create_tsfn(env, handler);
|
|
364
366
|
// register update handler
|
|
365
367
|
let mut builder = self.raw_builder.lock();
|
|
366
|
-
|
|
368
|
+
builder.handle_update_command(move |req: Update| {
|
|
367
369
|
let update = UpdateRequest {
|
|
368
370
|
version: req.version,
|
|
369
371
|
permit_major_version: req.permit_major_version,
|
|
@@ -385,14 +387,12 @@ impl NgrokSessionBuilder {
|
|
|
385
387
|
|
|
386
388
|
// register heartbeat handler
|
|
387
389
|
let mut builder = self.raw_builder.lock();
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
)
|
|
395
|
-
});
|
|
390
|
+
builder.handle_heartbeat(move |latency: Option<Duration>| {
|
|
391
|
+
call_tsfn(
|
|
392
|
+
tsfn.clone(),
|
|
393
|
+
vec![latency.map(|d| u32::try_from(d.as_millis()).ok())],
|
|
394
|
+
)
|
|
395
|
+
});
|
|
396
396
|
self
|
|
397
397
|
}
|
|
398
398
|
|
|
@@ -403,7 +403,7 @@ impl NgrokSessionBuilder {
|
|
|
403
403
|
// set default auth token if it exists
|
|
404
404
|
let default_auth_token = AUTH_TOKEN.lock().await;
|
|
405
405
|
if default_auth_token.is_some() && !self.auth_token_set {
|
|
406
|
-
builder
|
|
406
|
+
builder.authtoken(default_auth_token.as_ref().unwrap());
|
|
407
407
|
}
|
|
408
408
|
// connect to ngrok
|
|
409
409
|
builder
|
package/src/tcp.rs
CHANGED
|
@@ -9,7 +9,7 @@ impl NgrokTcpTunnelBuilder {
|
|
|
9
9
|
#[napi]
|
|
10
10
|
pub fn remote_addr(&mut self, remote_addr: String) -> &Self {
|
|
11
11
|
let mut builder = self.tunnel_builder.lock();
|
|
12
|
-
|
|
12
|
+
builder.remote_addr(remote_addr);
|
|
13
13
|
self
|
|
14
14
|
}
|
|
15
15
|
}
|
package/src/tls.rs
CHANGED
|
@@ -11,23 +11,21 @@ impl NgrokTlsTunnelBuilder {
|
|
|
11
11
|
#[napi]
|
|
12
12
|
pub fn domain(&mut self, domain: String) -> &Self {
|
|
13
13
|
let mut builder = self.tunnel_builder.lock();
|
|
14
|
-
|
|
14
|
+
builder.domain(domain);
|
|
15
15
|
self
|
|
16
16
|
}
|
|
17
17
|
/// Certificates to use for client authentication at the ngrok edge.
|
|
18
18
|
#[napi]
|
|
19
19
|
pub fn mutual_tlsca(&mut self, mutual_tlsca: Uint8Array) -> &Self {
|
|
20
20
|
let mut builder = self.tunnel_builder.lock();
|
|
21
|
-
|
|
22
|
-
.clone()
|
|
23
|
-
.mutual_tlsca(Bytes::from(mutual_tlsca.to_vec()));
|
|
21
|
+
builder.mutual_tlsca(Bytes::from(mutual_tlsca.to_vec()));
|
|
24
22
|
self
|
|
25
23
|
}
|
|
26
24
|
/// The certificate and key to use for TLS termination at the ngrok edge in PEM format.
|
|
27
25
|
#[napi]
|
|
28
26
|
pub fn termination(&mut self, cert_pem: Uint8Array, key_pem: Uint8Array) -> &Self {
|
|
29
27
|
let mut builder = self.tunnel_builder.lock();
|
|
30
|
-
|
|
28
|
+
builder.termination(
|
|
31
29
|
Bytes::from(cert_pem.to_vec()),
|
|
32
30
|
Bytes::from(key_pem.to_vec()),
|
|
33
31
|
);
|