@ngrok/ngrok 0.5.2 → 0.7.0
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 +41 -28
- package/CODE_OF_CONDUCT.md +45 -0
- package/Cargo.toml +8 -2
- package/README.md +161 -21
- package/docs/assets/highlight.css +13 -6
- package/docs/assets/search.js +1 -1
- package/docs/classes/NgrokHttpTunnelBuilder.html +59 -22
- package/docs/classes/NgrokLabeledTunnelBuilder.html +42 -5
- package/docs/classes/NgrokSession.html +24 -9
- package/docs/classes/NgrokSessionBuilder.html +20 -17
- package/docs/classes/NgrokTcpTunnelBuilder.html +46 -9
- package/docs/classes/NgrokTlsTunnelBuilder.html +48 -11
- package/docs/classes/NgrokTunnel.html +33 -35
- package/docs/classes/UpdateRequest.html +7 -4
- package/docs/functions/authtoken.html +5 -2
- package/docs/functions/connect.html +5 -2
- package/docs/functions/consoleLog.html +5 -2
- package/docs/functions/disconnect.html +5 -2
- package/docs/functions/getTunnel.html +88 -0
- package/docs/functions/getTunnelByUrl.html +88 -0
- package/docs/functions/kill.html +5 -2
- package/docs/functions/listen.html +5 -2
- package/docs/functions/listenable.html +5 -2
- package/docs/functions/loggingCallback.html +5 -2
- package/docs/functions/tunnels.html +83 -0
- package/docs/index.html +74 -13
- package/docs/interfaces/Config.html +57 -54
- package/docs/modules.html +7 -1
- package/examples/fastify/ngrok-fastify.js +1 -1
- package/examples/hapi/ngrok-hapi.js +1 -1
- package/examples/nestjs/src/main.ts +1 -1
- package/examples/nextjs/ngrok.config.js +1 -1
- package/examples/ngrok-connect-full.js +22 -23
- package/examples/ngrok-connect-minimal.js +3 -2
- package/examples/ngrok-http-full.js +1 -1
- package/examples/ngrok-http-minimum.js +1 -1
- package/examples/ngrok-labeled.js +1 -1
- package/examples/ngrok-tcp.js +1 -1
- package/examples/ngrok-tls.js +1 -1
- package/examples/ngrok-typescript.ts +1 -1
- package/examples/ngrok-windows-pipe.js +1 -1
- package/examples/remix/ngrok.config.js +1 -1
- package/examples/svelte/ngrok.config.cjs +1 -1
- package/examples/vue/ngrok.config.ts +1 -1
- package/index.d.ts +30 -6
- package/index.js +100 -22
- package/package.json +14 -14
- package/scripts/gc-node-drop.js +1 -1
- package/scripts/gc-rust-drop.js +1 -1
- package/src/connect.rs +17 -9
- package/src/http.rs +20 -22
- package/src/lib.rs +21 -0
- package/src/session.rs +61 -50
- package/src/tcp.rs +1 -1
- package/src/tls.rs +3 -5
- package/src/tunnel.rs +232 -110
- package/src/tunnel_builder.rs +34 -7
- package/trailer.js +96 -21
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! {
|
|
@@ -146,17 +147,14 @@ async fn async_connect(s_builder: NgrokSessionBuilder, config: Config) -> Result
|
|
|
146
147
|
_ => return Err(napi_err(format!("unhandled protocol {proto}"))),
|
|
147
148
|
};
|
|
148
149
|
|
|
149
|
-
let url = tunnel::
|
|
150
|
+
let url = tunnel::get_tunnel(id.clone())
|
|
151
|
+
.await
|
|
152
|
+
.and_then(|t| t.url())
|
|
153
|
+
.unwrap_or(id.clone());
|
|
150
154
|
|
|
151
155
|
// move forwarding to another task
|
|
152
156
|
if let Some(addr) = config.addr {
|
|
153
|
-
tokio::spawn(async move {
|
|
154
|
-
if addr.starts_with("pipe:") {
|
|
155
|
-
tunnel::forward_pipe(&id, addr.clone().split_off(5)).await
|
|
156
|
-
} else {
|
|
157
|
-
tunnel::forward_tcp(&id, addr).await
|
|
158
|
-
}
|
|
159
|
-
});
|
|
157
|
+
tokio::spawn(async move { tunnel::forward(&id, addr).await });
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
Ok(url)
|
|
@@ -261,13 +259,23 @@ fn set_defaults(config: &mut Config) {
|
|
|
261
259
|
}
|
|
262
260
|
if config.addr.is_none() {
|
|
263
261
|
if let Some(port) = &config.port {
|
|
264
|
-
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
|
+
}
|
|
265
267
|
} else if let Some(host) = &config.host {
|
|
266
268
|
config.addr.replace(host.clone());
|
|
267
269
|
} else {
|
|
268
270
|
config.addr.replace("80".to_string());
|
|
269
271
|
}
|
|
270
272
|
}
|
|
273
|
+
if let Some(addr) = &config.addr {
|
|
274
|
+
if addr.parse::<i32>().is_ok() {
|
|
275
|
+
// the string is a number, interpret it as a port
|
|
276
|
+
config.addr.replace(format!("{TCP_PREFIX}localhost:{addr}"));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
271
279
|
}
|
|
272
280
|
|
|
273
281
|
/// Warn about unused configuration values
|
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
|
@@ -2,6 +2,7 @@ use napi::{
|
|
|
2
2
|
Error,
|
|
3
3
|
Status,
|
|
4
4
|
};
|
|
5
|
+
use ngrok::prelude::Error as NgrokError;
|
|
5
6
|
|
|
6
7
|
pub mod config;
|
|
7
8
|
pub mod connect;
|
|
@@ -16,3 +17,23 @@ pub mod tunnel_builder;
|
|
|
16
17
|
pub(crate) fn napi_err(message: impl Into<String>) -> Error {
|
|
17
18
|
Error::new(Status::GenericFailure, message.into())
|
|
18
19
|
}
|
|
20
|
+
|
|
21
|
+
pub(crate) fn napi_ngrok_err(message: impl Into<String>, err: &impl NgrokError) -> Error {
|
|
22
|
+
let py_err = if let Some(error_code) = err.error_code() {
|
|
23
|
+
Error::new(
|
|
24
|
+
Status::GenericFailure,
|
|
25
|
+
format!(
|
|
26
|
+
"{}: {} error_code: {}",
|
|
27
|
+
message.into(),
|
|
28
|
+
err.msg(),
|
|
29
|
+
error_code
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
} else {
|
|
33
|
+
Error::new(
|
|
34
|
+
Status::GenericFailure,
|
|
35
|
+
format!("{}: {}", message.into(), err.msg()),
|
|
36
|
+
)
|
|
37
|
+
};
|
|
38
|
+
py_err
|
|
39
|
+
}
|
package/src/session.rs
CHANGED
|
@@ -35,7 +35,12 @@ use tracing::{
|
|
|
35
35
|
|
|
36
36
|
use crate::{
|
|
37
37
|
napi_err,
|
|
38
|
-
|
|
38
|
+
napi_ngrok_err,
|
|
39
|
+
tunnel::{
|
|
40
|
+
remove_global_tunnel,
|
|
41
|
+
search_tunnels,
|
|
42
|
+
NgrokTunnel,
|
|
43
|
+
},
|
|
39
44
|
tunnel_builder::{
|
|
40
45
|
NgrokHttpTunnelBuilder,
|
|
41
46
|
NgrokLabeledTunnelBuilder,
|
|
@@ -84,11 +89,11 @@ impl NgrokSessionBuilder {
|
|
|
84
89
|
#[napi(constructor)]
|
|
85
90
|
pub fn new() -> Self {
|
|
86
91
|
NgrokSessionBuilder {
|
|
87
|
-
raw_builder: Arc::new(SyncMutex::new(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
))
|
|
92
|
+
raw_builder: Arc::new(SyncMutex::new(
|
|
93
|
+
Session::builder()
|
|
94
|
+
.client_info(CLIENT_TYPE, VERSION, None::<String>)
|
|
95
|
+
.clone(),
|
|
96
|
+
)),
|
|
92
97
|
..Default::default()
|
|
93
98
|
}
|
|
94
99
|
}
|
|
@@ -105,7 +110,7 @@ impl NgrokSessionBuilder {
|
|
|
105
110
|
#[napi]
|
|
106
111
|
pub fn authtoken(&mut self, authtoken: String) -> &Self {
|
|
107
112
|
let mut builder = self.raw_builder.lock();
|
|
108
|
-
|
|
113
|
+
builder.authtoken(authtoken);
|
|
109
114
|
self.auth_token_set = true;
|
|
110
115
|
self
|
|
111
116
|
}
|
|
@@ -115,7 +120,7 @@ impl NgrokSessionBuilder {
|
|
|
115
120
|
#[napi]
|
|
116
121
|
pub fn authtoken_from_env(&mut self) -> &Self {
|
|
117
122
|
let mut builder = self.raw_builder.lock();
|
|
118
|
-
|
|
123
|
+
builder.authtoken_from_env();
|
|
119
124
|
self.auth_token_set = true;
|
|
120
125
|
self
|
|
121
126
|
}
|
|
@@ -137,7 +142,7 @@ impl NgrokSessionBuilder {
|
|
|
137
142
|
comments: Option<String>,
|
|
138
143
|
) -> &Self {
|
|
139
144
|
let mut builder = self.raw_builder.lock();
|
|
140
|
-
|
|
145
|
+
builder.client_info(client_type, version, comments);
|
|
141
146
|
self
|
|
142
147
|
}
|
|
143
148
|
|
|
@@ -149,12 +154,12 @@ impl NgrokSessionBuilder {
|
|
|
149
154
|
///
|
|
150
155
|
/// [heartbeat_interval parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_interval
|
|
151
156
|
#[napi]
|
|
152
|
-
pub fn heartbeat_interval(&mut self, heartbeat_interval: u32) ->
|
|
157
|
+
pub fn heartbeat_interval(&mut self, heartbeat_interval: u32) -> Result<&Self> {
|
|
153
158
|
let mut builder = self.raw_builder.lock();
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
.
|
|
157
|
-
self
|
|
159
|
+
builder
|
|
160
|
+
.heartbeat_interval(Duration::new(heartbeat_interval.into(), 0))
|
|
161
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
162
|
+
Ok(self)
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
/// Configures the duration to wait for a response to a heartbeat before
|
|
@@ -165,12 +170,12 @@ impl NgrokSessionBuilder {
|
|
|
165
170
|
///
|
|
166
171
|
/// [heartbeat_tolerance parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_tolerance
|
|
167
172
|
#[napi]
|
|
168
|
-
pub fn heartbeat_tolerance(&mut self, heartbeat_tolerance: u32) ->
|
|
173
|
+
pub fn heartbeat_tolerance(&mut self, heartbeat_tolerance: u32) -> Result<&Self> {
|
|
169
174
|
let mut builder = self.raw_builder.lock();
|
|
170
|
-
|
|
171
|
-
.
|
|
172
|
-
.
|
|
173
|
-
self
|
|
175
|
+
builder
|
|
176
|
+
.heartbeat_tolerance(Duration::new(heartbeat_tolerance.into(), 0))
|
|
177
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
178
|
+
Ok(self)
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
/// Configures the opaque, machine-readable metadata string for this session.
|
|
@@ -184,7 +189,7 @@ impl NgrokSessionBuilder {
|
|
|
184
189
|
#[napi]
|
|
185
190
|
pub fn metadata(&mut self, metadata: String) -> &Self {
|
|
186
191
|
let mut builder = self.raw_builder.lock();
|
|
187
|
-
|
|
192
|
+
builder.metadata(metadata);
|
|
188
193
|
self
|
|
189
194
|
}
|
|
190
195
|
|
|
@@ -195,10 +200,12 @@ impl NgrokSessionBuilder {
|
|
|
195
200
|
///
|
|
196
201
|
/// [server_addr parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#server_addr
|
|
197
202
|
#[napi]
|
|
198
|
-
pub fn server_addr(&mut self, addr: String) ->
|
|
203
|
+
pub fn server_addr(&mut self, addr: String) -> Result<&Self> {
|
|
199
204
|
let mut builder = self.raw_builder.lock();
|
|
200
|
-
|
|
201
|
-
|
|
205
|
+
builder
|
|
206
|
+
.server_addr(addr)
|
|
207
|
+
.map_err(|e| napi_err(format!("{e}")))?;
|
|
208
|
+
Ok(self)
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
/// Configures the TLS certificate used to connect to the ngrok service while
|
|
@@ -213,7 +220,7 @@ impl NgrokSessionBuilder {
|
|
|
213
220
|
#[napi]
|
|
214
221
|
pub fn ca_cert(&mut self, cert_bytes: Uint8Array) -> &Self {
|
|
215
222
|
let mut builder = self.raw_builder.lock();
|
|
216
|
-
|
|
223
|
+
builder.ca_cert(Bytes::from(cert_bytes.to_vec()));
|
|
217
224
|
self
|
|
218
225
|
}
|
|
219
226
|
|
|
@@ -245,8 +252,11 @@ impl NgrokSessionBuilder {
|
|
|
245
252
|
// clone for move to connector function
|
|
246
253
|
let connect_handler = self.connect_handler.clone();
|
|
247
254
|
let disconnect_handler = self.disconnect_handler.clone();
|
|
248
|
-
|
|
249
|
-
move |
|
|
255
|
+
builder.connector(
|
|
256
|
+
move |host: String,
|
|
257
|
+
port: u16,
|
|
258
|
+
tls_config: Arc<ClientConfig>,
|
|
259
|
+
err: Option<AcceptError>| {
|
|
250
260
|
// clone for async move out of environment
|
|
251
261
|
let conn_tsfn = connect_handler.clone();
|
|
252
262
|
let disconn_tsfn = disconnect_handler.clone();
|
|
@@ -259,21 +269,21 @@ impl NgrokSessionBuilder {
|
|
|
259
269
|
.clone()
|
|
260
270
|
.lock()
|
|
261
271
|
.await
|
|
262
|
-
.call_async(vec![
|
|
272
|
+
.call_async(vec![format!("{host}:{port}"), err.to_string()])
|
|
263
273
|
.await
|
|
264
274
|
.map_err(|_e| ConnectError::Canceled)?;
|
|
265
275
|
|
|
266
276
|
if let Some(reconnect) = resp {
|
|
267
277
|
if !reconnect {
|
|
268
|
-
info!("Aborting connection to {
|
|
269
|
-
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
|
|
270
280
|
return Err(ConnectError::Canceled);
|
|
271
281
|
}
|
|
272
282
|
}
|
|
273
283
|
};
|
|
274
284
|
}
|
|
275
285
|
// call the upstream connector
|
|
276
|
-
let res = default_connect(
|
|
286
|
+
let res = default_connect(host, port, tls_config, err).await;
|
|
277
287
|
|
|
278
288
|
// call connect handler
|
|
279
289
|
if let Some(handler) = conn_tsfn {
|
|
@@ -313,9 +323,7 @@ impl NgrokSessionBuilder {
|
|
|
313
323
|
let tsfn = create_tsfn(env, handler);
|
|
314
324
|
// register stop handler
|
|
315
325
|
let mut builder = self.raw_builder.lock();
|
|
316
|
-
|
|
317
|
-
.clone()
|
|
318
|
-
.handle_stop_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
326
|
+
builder.handle_stop_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
319
327
|
self
|
|
320
328
|
}
|
|
321
329
|
|
|
@@ -336,9 +344,7 @@ impl NgrokSessionBuilder {
|
|
|
336
344
|
let tsfn = create_tsfn(env, handler);
|
|
337
345
|
// register restart handler
|
|
338
346
|
let mut builder = self.raw_builder.lock();
|
|
339
|
-
|
|
340
|
-
.clone()
|
|
341
|
-
.handle_restart_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
347
|
+
builder.handle_restart_command(move |_req| call_tsfn(tsfn.clone(), vec![()]));
|
|
342
348
|
self
|
|
343
349
|
}
|
|
344
350
|
|
|
@@ -359,7 +365,7 @@ impl NgrokSessionBuilder {
|
|
|
359
365
|
let tsfn = create_tsfn(env, handler);
|
|
360
366
|
// register update handler
|
|
361
367
|
let mut builder = self.raw_builder.lock();
|
|
362
|
-
|
|
368
|
+
builder.handle_update_command(move |req: Update| {
|
|
363
369
|
let update = UpdateRequest {
|
|
364
370
|
version: req.version,
|
|
365
371
|
permit_major_version: req.permit_major_version,
|
|
@@ -381,14 +387,12 @@ impl NgrokSessionBuilder {
|
|
|
381
387
|
|
|
382
388
|
// register heartbeat handler
|
|
383
389
|
let mut builder = self.raw_builder.lock();
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
)
|
|
391
|
-
});
|
|
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
|
+
});
|
|
392
396
|
self
|
|
393
397
|
}
|
|
394
398
|
|
|
@@ -399,19 +403,19 @@ impl NgrokSessionBuilder {
|
|
|
399
403
|
// set default auth token if it exists
|
|
400
404
|
let default_auth_token = AUTH_TOKEN.lock().await;
|
|
401
405
|
if default_auth_token.is_some() && !self.auth_token_set {
|
|
402
|
-
builder
|
|
406
|
+
builder.authtoken(default_auth_token.as_ref().unwrap());
|
|
403
407
|
}
|
|
404
408
|
// connect to ngrok
|
|
405
409
|
builder
|
|
406
410
|
.connect()
|
|
407
411
|
.await
|
|
408
412
|
.map(|s| {
|
|
409
|
-
info!("Session created");
|
|
413
|
+
info!("Session created {:?}", s.id());
|
|
410
414
|
NgrokSession {
|
|
411
415
|
raw_session: Arc::new(SyncMutex::new(s)),
|
|
412
416
|
}
|
|
413
417
|
})
|
|
414
|
-
.map_err(|e|
|
|
418
|
+
.map_err(|e| napi_ngrok_err("failed to connect session", &e))
|
|
415
419
|
}
|
|
416
420
|
}
|
|
417
421
|
|
|
@@ -455,6 +459,13 @@ impl NgrokSession {
|
|
|
455
459
|
NgrokLabeledTunnelBuilder::new(session.clone(), session.labeled_tunnel())
|
|
456
460
|
}
|
|
457
461
|
|
|
462
|
+
/// Retrieve a list of this session's non-closed tunnels, in no particular order.
|
|
463
|
+
#[napi]
|
|
464
|
+
pub async fn tunnels(&self) -> Vec<NgrokTunnel> {
|
|
465
|
+
let session_id = self.raw_session.lock().id();
|
|
466
|
+
search_tunnels(Some(session_id), None).await
|
|
467
|
+
}
|
|
468
|
+
|
|
458
469
|
/// Close a tunnel with the given ID.
|
|
459
470
|
#[napi]
|
|
460
471
|
pub async fn close_tunnel(&self, id: String) -> Result<()> {
|
|
@@ -463,7 +474,7 @@ impl NgrokSession {
|
|
|
463
474
|
let res = session
|
|
464
475
|
.close_tunnel(id.clone())
|
|
465
476
|
.await
|
|
466
|
-
.map_err(|e|
|
|
477
|
+
.map_err(|e| napi_ngrok_err("failed to close tunnel", &e));
|
|
467
478
|
|
|
468
479
|
if res.is_ok() {
|
|
469
480
|
// remove our reference to allow it to drop
|
|
@@ -479,7 +490,7 @@ impl NgrokSession {
|
|
|
479
490
|
session
|
|
480
491
|
.close()
|
|
481
492
|
.await
|
|
482
|
-
.map_err(|e|
|
|
493
|
+
.map_err(|e| napi_ngrok_err("failed to close session", &e))
|
|
483
494
|
}
|
|
484
495
|
}
|
|
485
496
|
|
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
|
);
|