@ngrok/ngrok 0.2.0 → 0.4.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Cargo.toml +1 -1
  3. package/README.md +17 -10
  4. package/docs/assets/highlight.css +13 -6
  5. package/docs/assets/main.js +3 -3
  6. package/docs/assets/search.js +1 -1
  7. package/docs/assets/style.css +450 -362
  8. package/docs/classes/NgrokHttpTunnelBuilder.html +232 -199
  9. package/docs/classes/NgrokLabeledTunnelBuilder.html +81 -49
  10. package/docs/classes/NgrokSession.html +96 -66
  11. package/docs/classes/NgrokSessionBuilder.html +168 -138
  12. package/docs/classes/NgrokTcpTunnelBuilder.html +112 -80
  13. package/docs/classes/NgrokTlsTunnelBuilder.html +130 -98
  14. package/docs/classes/NgrokTunnel.html +233 -0
  15. package/docs/classes/UpdateRequest.html +66 -33
  16. package/docs/functions/authtoken.html +85 -0
  17. package/docs/functions/connect.html +85 -0
  18. package/docs/functions/consoleLog.html +47 -34
  19. package/docs/functions/disconnect.html +85 -0
  20. package/docs/functions/kill.html +80 -0
  21. package/docs/functions/listen.html +51 -37
  22. package/docs/functions/listenable.html +49 -40
  23. package/docs/functions/loggingCallback.html +53 -40
  24. package/docs/index.html +91 -101
  25. package/docs/interfaces/Config.html +605 -0
  26. package/docs/modules.html +67 -46
  27. package/examples/ngrok-connect-full.js +64 -0
  28. package/examples/ngrok-connect-minimal.js +16 -0
  29. package/examples/ngrok-http-full.js +9 -11
  30. package/examples/ngrok-http-minimum.js +8 -12
  31. package/examples/ngrok-labeled.js +5 -5
  32. package/examples/ngrok-listen.js +2 -2
  33. package/examples/ngrok-tcp.js +5 -6
  34. package/examples/ngrok-tls.js +5 -5
  35. package/examples/ngrok-typescript.ts +3 -3
  36. package/examples/ngrok-windows-pipe.js +1 -1
  37. package/examples/ngrok-winston.js +2 -2
  38. package/index.d.ts +233 -124
  39. package/index.js +119 -7
  40. package/package.json +17 -16
  41. package/src/config.rs +182 -0
  42. package/src/connect.rs +328 -0
  43. package/src/http.rs +5 -4
  44. package/src/lib.rs +2 -0
  45. package/src/session.rs +59 -4
  46. package/src/tls.rs +1 -1
  47. package/src/tunnel.rs +210 -136
  48. package/src/tunnel_builder.rs +11 -2
  49. package/trailer.d.ts +11 -7
  50. package/trailer.js +113 -2
  51. package/typedoc.json +3 -0
  52. package/docs/classes/NgrokHttpTunnel.html +0 -191
  53. package/docs/classes/NgrokLabeledTunnel.html +0 -179
  54. package/docs/classes/NgrokTcpTunnel.html +0 -191
  55. package/docs/classes/NgrokTlsTunnel.html +0 -191
package/src/config.rs ADDED
@@ -0,0 +1,182 @@
1
+ use napi_derive::napi;
2
+
3
+ /// Configuration object to pass to ngrok.connect()
4
+ ///
5
+ /// @group Functions
6
+ #[napi(object)]
7
+ #[derive(Default)]
8
+ pub struct Config {
9
+ /// Port, network address, or named pipe. Defaults to 80.
10
+ /// Examples: "80", "localhost:8080", "pipe:/tmp/my.sock"
11
+ #[napi(ts_type = "number|string")]
12
+ pub addr: Option<String>,
13
+ // Synonym for basic_auth
14
+ #[napi(ts_type = "string|Array<string>")]
15
+ pub auth: Option<Vec<String>>,
16
+ /// Configures the session to authenticate with the provided authtoken. You
17
+ /// can [find your existing authtoken] or [create a new one] in the ngrok
18
+ /// dashboard.
19
+ ///
20
+ /// See the [authtoken parameter in the ngrok docs] for additional details.
21
+ ///
22
+ /// [find your existing authtoken]: https://dashboard.ngrok.com/get-started/your-authtoken
23
+ /// [create a new one]: https://dashboard.ngrok.com/tunnels/authtokens
24
+ /// [authtoken parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#authtoken
25
+ pub authtoken: Option<String>,
26
+ /// Shortcut for calling [SessionBuilder::authtoken] with the value of the
27
+ /// NGROK_AUTHTOKEN environment variable.
28
+ #[napi(js_name = "authtoken_from_env")]
29
+ pub authtoken_from_env: Option<bool>,
30
+ /// Credentials for basic authentication, with username and password colon separated.
31
+ #[napi(js_name = "basic_auth", ts_type = "string|Array<string>")]
32
+ pub basic_auth: Option<Vec<String>>,
33
+ /// Unused, will warn and be ignored
34
+ pub bin_path: Option<String>,
35
+ /// Reject requests when 5XX responses exceed this ratio.
36
+ /// Disabled when 0.
37
+ #[napi(js_name = "circuit_breaker")]
38
+ pub circuit_breaker: Option<f64>,
39
+ /// Enable gzip compression for HTTP responses.
40
+ pub compression: Option<bool>,
41
+ /// Unused, will warn and be ignored
42
+ pub config_path: Option<String>,
43
+ /// The certificate to use for TLS termination at the ngrok edge in PEM format.
44
+ /// Only used if "proto" is "tls".
45
+ pub crt: Option<String>,
46
+ /// The domain to request for this edge.
47
+ pub domain: Option<String>,
48
+ /// Returns a human-readable string presented in the ngrok dashboard
49
+ /// and the Tunnels API.
50
+ #[napi(js_name = "forwards_to")]
51
+ pub forwards_to: Option<String>,
52
+ /// Unused, will warn and be ignored
53
+ #[napi(js_name = "host_header")]
54
+ pub host_header: Option<String>,
55
+ /// The hostname for the tunnel to forward to.
56
+ /// Only used if addr is not defined.
57
+ pub host: Option<String>,
58
+ /// Synonym for domain
59
+ pub hostname: Option<String>,
60
+ /// Unused, will warn and be ignored
61
+ pub inspect: Option<String>,
62
+ /// Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
63
+ #[napi(
64
+ js_name = "ip_restriction_allow_cidrs",
65
+ ts_type = "string|Array<string>"
66
+ )]
67
+ pub allow_cidr: Option<Vec<String>>,
68
+ /// Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges.
69
+ #[napi(
70
+ js_name = "ip_restriction_deny_cidrs",
71
+ ts_type = "string|Array<string>"
72
+ )]
73
+ pub deny_cidr: Option<Vec<String>>,
74
+ /// The certificate to use for TLS termination at the ngrok edge in PEM format.
75
+ /// Only used if "proto" is "tls".
76
+ pub key: Option<String>,
77
+ /// Add label, value pairs for this tunnel, colon separated.
78
+ #[napi(ts_type = "string|Array<string>")]
79
+ pub labels: Option<Vec<String>>,
80
+ /// Tunnel-specific opaque metadata. Viewable via the API.
81
+ pub metadata: Option<String>,
82
+ /// Certificates to use for client authentication at the ngrok edge.
83
+ /// Only used if "proto" is "tls" or "http".
84
+ #[napi(js_name = "mutual_tls_cas", ts_type = "string|Array<string>")]
85
+ pub mutual_tls_cas: Option<Vec<String>>,
86
+ /// Unused, will warn and be ignored
87
+ pub name: Option<String>,
88
+ /// OAuth configuration of domains to allow.
89
+ #[napi(js_name = "oauth_allow_domains", ts_type = "string|Array<string>")]
90
+ pub oauth_allow_domains: Option<Vec<String>>,
91
+ /// OAuth configuration of email addresses to allow.
92
+ #[napi(js_name = "oauth_allow_emails", ts_type = "string|Array<string>")]
93
+ pub oauth_allow_emails: Option<Vec<String>>,
94
+ /// OAuth configuration of scopes.
95
+ #[napi(js_name = "oauth_scopes", ts_type = "string|Array<string>")]
96
+ pub oauth_scopes: Option<Vec<String>>,
97
+ /// OAuth configuration of the provider, e.g. "google".
98
+ /// https://ngrok.com/docs/cloud-edge/modules/oauth/
99
+ #[napi(js_name = "oauth_provider")]
100
+ pub oauth_provider: Option<String>,
101
+ /// OIDC configuration of client ID.
102
+ #[napi(js_name = "oidc_client_id")]
103
+ pub oidc_client_id: Option<String>,
104
+ /// OIDC configuration of client secret.
105
+ #[napi(js_name = "oidc_client_secret")]
106
+ pub oidc_client_secret: Option<String>,
107
+ /// OIDC configuration of scopes.
108
+ #[napi(js_name = "oidc_scopes", ts_type = "string|Array<string>")]
109
+ pub oidc_scopes: Option<Vec<String>>,
110
+ /// OIDC configuration of the issuer URL.
111
+ #[napi(js_name = "oidc_issuer_url")]
112
+ pub oidc_issuer_url: Option<String>,
113
+ /// OIDC configuration of domains to allow.
114
+ #[napi(js_name = "oidc_allow_domains", ts_type = "string|Array<string>")]
115
+ pub oidc_allow_domains: Option<Vec<String>>,
116
+ /// OIDC configuration of email addresses to allow.
117
+ #[napi(js_name = "oidc_allow_emails", ts_type = "string|Array<string>")]
118
+ pub oidc_allow_emails: Option<Vec<String>>,
119
+ /// Returns log messages from the ngrok library.
120
+ #[napi(ts_type = "(data: string) => void")]
121
+ pub on_log_event: Option<bool>,
122
+ /// 'closed' - connection is lost, 'connected' - reconnected
123
+ #[napi(ts_type = "(status: string) => void")]
124
+ pub on_status_change: Option<bool>,
125
+ /// The port for the tunnel to forward to.
126
+ /// Only used if addr is not defined.
127
+ pub port: Option<u32>,
128
+ /// The type of tunnel to use, one of http|tcp|tls|labeled, defaults to http.
129
+ pub proto: Option<String>,
130
+ /// The version of PROXY protocol to use with this tunnel "1", "2", or "" if not using.
131
+ #[napi(js_name = "proxy_proto")]
132
+ pub proxy_proto: Option<String>,
133
+ /// Adds a header to all requests to this edge.
134
+ #[napi(js_name = "request_header_add", ts_type = "string|Array<string>")]
135
+ pub request_header_add: Option<Vec<String>>,
136
+ /// Removes a header from requests to this edge.
137
+ #[napi(js_name = "request_header_remove", ts_type = "string|Array<string>")]
138
+ pub request_header_remove: Option<Vec<String>>,
139
+ /// Adds a header to all responses coming from this edge.
140
+ #[napi(js_name = "response_header_add", ts_type = "string|Array<string>")]
141
+ pub response_header_add: Option<Vec<String>>,
142
+ /// Removes a header from responses from this edge.
143
+ #[napi(js_name = "response_header_remove", ts_type = "string|Array<string>")]
144
+ pub response_header_remove: Option<Vec<String>>,
145
+ /// Unused, will warn and be ignored
146
+ pub region: Option<String>,
147
+ /// The TCP address to request for this edge.
148
+ /// Only used if proto is "tcp".
149
+ #[napi(js_name = "remote_addr")]
150
+ pub remote_addr: Option<String>,
151
+ /// The scheme that this edge should use, defaults to "https".
152
+ /// If multiple are given only the last one is used.
153
+ #[napi(ts_type = "string|Array<string>")]
154
+ pub schemes: Option<Vec<String>>,
155
+ /// Configures the opaque, machine-readable metadata string for this session.
156
+ /// Metadata is made available to you in the ngrok dashboard and the Agents API
157
+ /// resource. It is a useful way to allow you to uniquely identify sessions. We
158
+ /// suggest encoding the value in a structured format like JSON.
159
+ ///
160
+ /// See the [metdata parameter in the ngrok docs] for additional details.
161
+ ///
162
+ /// [metdata parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#metadata
163
+ #[napi(js_name = "session_metadata")]
164
+ pub session_metadata: Option<String>,
165
+ /// Unused, use domain instead, will warn and be ignored
166
+ pub subdomain: Option<String>,
167
+ /// Unused, will warn and be ignored
168
+ #[napi(js_name = "terminate_at")]
169
+ pub terminate_at: Option<String>,
170
+ /// WebhookVerification configuration, the provider to use.
171
+ #[napi(js_name = "verify_webhook_provider")]
172
+ pub verify_webhook_provider: Option<String>,
173
+ /// WebhookVerification configuration, the secret to use.
174
+ #[napi(js_name = "verify_webhook_secret")]
175
+ pub verify_webhook_secret: Option<String>,
176
+ /// Unused, will warn and be ignored
177
+ #[napi(js_name = "web_addr")]
178
+ pub web_addr: Option<String>,
179
+ /// Convert incoming websocket connections to TCP-like streams.
180
+ #[napi(js_name = "websocket_tcp_converter")]
181
+ pub websocket_tcp_converter: Option<bool>,
182
+ }
package/src/connect.rs ADDED
@@ -0,0 +1,328 @@
1
+ use lazy_static::lazy_static;
2
+ use napi::{
3
+ bindgen_prelude::*,
4
+ JsObject,
5
+ };
6
+ use napi_derive::napi;
7
+ use tokio::sync::Mutex;
8
+ use tracing::warn;
9
+
10
+ use crate::{
11
+ config::Config,
12
+ logging::logging_callback,
13
+ napi_err,
14
+ session::{
15
+ NgrokSession,
16
+ NgrokSessionBuilder,
17
+ },
18
+ tunnel,
19
+ };
20
+
21
+ lazy_static! {
22
+ // Save a user-facing NgrokSession to use for connect use cases
23
+ pub(crate) static ref SESSION: Mutex<Option<NgrokSession>> = Mutex::new(None);
24
+ }
25
+
26
+ /// Single string configuration
27
+ macro_rules! plumb {
28
+ ($builder:tt, $config:tt, $name:tt) => {
29
+ plumb!($builder, $config, $name, $name)
30
+ };
31
+ ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
32
+ if let Some(ref $name) = $config.$config_name {
33
+ $builder.$name($name.clone());
34
+ }
35
+ };
36
+ }
37
+
38
+ /// Boolean configuration
39
+ macro_rules! plumb_bool {
40
+ ($builder:tt, $config:tt, $name:tt) => {
41
+ plumb_bool!($builder, $config, $name, $name)
42
+ };
43
+ ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
44
+ if let Some($name) = $config.$config_name {
45
+ if $name {
46
+ $builder.$name();
47
+ }
48
+ }
49
+ };
50
+ }
51
+
52
+ /// Vector configuration
53
+ macro_rules! plumb_vec {
54
+ ($builder:tt, $config:tt, $name:tt) => {
55
+ plumb_vec!($builder, $config, $name, $name)
56
+ };
57
+ ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
58
+ if let Some(ref $name) = $config.$config_name {
59
+ for val in $name {
60
+ $builder.$name(val.clone());
61
+ }
62
+ }
63
+ };
64
+ ($builder:tt, $config:tt, $name:tt, $config_name:tt, vecu8) => {
65
+ if let Some(ref $name) = $config.$config_name {
66
+ for val in $name {
67
+ $builder.$name(Uint8Array::new(val.as_bytes().to_vec()));
68
+ }
69
+ }
70
+ };
71
+ ($builder:tt, $config:tt, $name:tt, $config_name:tt, $split:tt) => {
72
+ if let Some(ref $name) = $config.$config_name {
73
+ for val in $name {
74
+ let (a, b) = val
75
+ .split_once($split)
76
+ .expect("split of value failed: ${val}");
77
+ $builder.$name(a.to_string(), b.to_string());
78
+ }
79
+ }
80
+ };
81
+ }
82
+
83
+ /// All non-labeled tunnels have these common configuration options
84
+ macro_rules! config_common {
85
+ ($builder:tt, $config:tt) => {
86
+ plumb!($builder, $config, metadata);
87
+ plumb_vec!($builder, $config, allow_cidr);
88
+ plumb_vec!($builder, $config, deny_cidr);
89
+ plumb!($builder, $config, proxy_proto);
90
+ plumb!($builder, $config, forwards_to);
91
+ };
92
+ }
93
+
94
+ /// Transform a json object configuration into a tunnel
95
+ #[napi(
96
+ ts_args_type = "config: Config|string|number",
97
+ ts_return_type = "Promise<string>"
98
+ )]
99
+ #[allow(dead_code)]
100
+ pub fn connect(
101
+ env: Env,
102
+ mut cfg: Config,
103
+ on_log_event: Option<JsFunction>,
104
+ on_connection: Option<JsFunction>,
105
+ on_disconnection: Option<JsFunction>,
106
+ ) -> Result<JsObject> {
107
+ // do logging configuration before anything else
108
+ if on_log_event.is_some() {
109
+ logging_callback(env, on_log_event, None)?;
110
+ }
111
+ warn_unused(&cfg);
112
+ set_defaults(&mut cfg);
113
+
114
+ // session configuration
115
+ let mut s_builder = NgrokSessionBuilder::new();
116
+ plumb!(s_builder, cfg, authtoken);
117
+ plumb_bool!(s_builder, cfg, authtoken_from_env);
118
+ plumb!(s_builder, cfg, metadata, session_metadata);
119
+ if let Some(func) = on_connection {
120
+ s_builder.handle_connection(env, func);
121
+ }
122
+ if let Some(func) = on_disconnection {
123
+ s_builder.handle_disconnection(env, func);
124
+ }
125
+
126
+ // no longer need Env, hand off to async for tunnel creation, returning the promise to nodejs.
127
+ env.spawn_future(async_connect(s_builder, cfg))
128
+ }
129
+
130
+ /// Connect the session, configure and start the tunnel
131
+ async fn async_connect(s_builder: NgrokSessionBuilder, config: Config) -> Result<String> {
132
+ // Using a singleton session for connect use cases
133
+ let mut opt = SESSION.lock().await;
134
+ if opt.is_none() {
135
+ opt.replace(s_builder.connect().await?);
136
+ }
137
+ let session = opt.as_ref().unwrap();
138
+
139
+ // tunnel configuration dispatch
140
+ let proto = config.proto.as_ref().unwrap();
141
+ let id = match proto.as_str() {
142
+ "http" => http_endpoint(session, &config).await?,
143
+ "tcp" => tcp_endpoint(session, &config).await?,
144
+ "tls" => tls_endpoint(session, &config).await?,
145
+ "labeled" => labeled_tunnel(session, &config).await?,
146
+ _ => return Err(napi_err(format!("unhandled protocol {proto}"))),
147
+ };
148
+
149
+ let url = tunnel::get_url(&id).await.expect("no url found");
150
+
151
+ // move forwarding to another task
152
+ 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
+ });
160
+ }
161
+
162
+ Ok(url)
163
+ }
164
+
165
+ /// HTTP Tunnel configuration
166
+ async fn http_endpoint(session: &NgrokSession, cfg: &Config) -> Result<String> {
167
+ let mut bld = session.http_endpoint();
168
+ config_common!(bld, cfg);
169
+ plumb_vec!(bld, cfg, scheme, schemes);
170
+ plumb!(bld, cfg, domain, hostname); // synonym for domain
171
+ plumb!(bld, cfg, domain);
172
+ plumb_vec!(bld, cfg, mutual_tlsca, mutual_tls_cas, vecu8);
173
+ plumb_bool!(bld, cfg, compression);
174
+ plumb_bool!(bld, cfg, websocket_tcp_conversion, websocket_tcp_converter);
175
+ plumb_vec!(bld, cfg, request_header, request_header_add, ":");
176
+ plumb_vec!(bld, cfg, response_header, response_header_add, ":");
177
+ plumb_vec!(bld, cfg, remove_request_header, request_header_remove);
178
+ plumb_vec!(bld, cfg, remove_response_header, response_header_remove);
179
+ plumb_vec!(bld, cfg, basic_auth, basic_auth, ":");
180
+ // circuit breaker
181
+ if let Some(circuit_breaker) = cfg.circuit_breaker {
182
+ bld.circuit_breaker(circuit_breaker);
183
+ }
184
+ // oauth
185
+ if let Some(ref provider) = cfg.oauth_provider {
186
+ bld.oauth(
187
+ provider.clone(),
188
+ cfg.oauth_allow_emails.clone(),
189
+ cfg.oauth_allow_domains.clone(),
190
+ cfg.oauth_scopes.clone(),
191
+ );
192
+ }
193
+ // oidc
194
+ if let Some(ref issuer_url) = cfg.oidc_issuer_url {
195
+ if cfg.oidc_client_id.is_none() {
196
+ return Err(napi_err("Missing client id for oidc"));
197
+ }
198
+ if cfg.oidc_client_secret.is_none() {
199
+ return Err(napi_err("Missing client secret for oidc"));
200
+ }
201
+ bld.oidc(
202
+ issuer_url.clone(),
203
+ cfg.oidc_client_id.clone().unwrap(),
204
+ cfg.oidc_client_secret.clone().unwrap(),
205
+ cfg.oidc_allow_emails.clone(),
206
+ cfg.oidc_allow_domains.clone(),
207
+ cfg.oidc_scopes.clone(),
208
+ );
209
+ }
210
+ // webhook verification
211
+ if let Some(ref provider) = cfg.verify_webhook_provider {
212
+ if let Some(ref secret) = cfg.verify_webhook_secret {
213
+ bld.webhook_verification(provider.clone(), secret.clone());
214
+ } else {
215
+ return Err(napi_err("Missing secret for webhook verification"));
216
+ }
217
+ }
218
+ Ok(bld.listen(None).await?.id())
219
+ }
220
+
221
+ /// TCP Tunnel configuration
222
+ async fn tcp_endpoint(session: &NgrokSession, cfg: &Config) -> Result<String> {
223
+ let mut bld = session.tcp_endpoint();
224
+ config_common!(bld, cfg);
225
+ plumb!(bld, cfg, remote_addr);
226
+ Ok(bld.listen(None).await?.id())
227
+ }
228
+
229
+ /// TLS Tunnel configuration
230
+ async fn tls_endpoint(session: &NgrokSession, cfg: &Config) -> Result<String> {
231
+ let mut bld = session.tls_endpoint();
232
+ config_common!(bld, cfg);
233
+ plumb!(bld, cfg, domain, hostname); // synonym for domain
234
+ plumb!(bld, cfg, domain);
235
+ plumb_vec!(bld, cfg, mutual_tlsca, mutual_tls_cas, vecu8);
236
+ if let Some(ref crt) = cfg.crt {
237
+ if let Some(ref key) = cfg.key {
238
+ bld.termination(
239
+ Uint8Array::new(crt.as_bytes().to_vec()),
240
+ Uint8Array::new(key.as_bytes().to_vec()),
241
+ );
242
+ } else {
243
+ return Err(napi_err("Missing key for tls termination"));
244
+ }
245
+ }
246
+ Ok(bld.listen(None).await?.id())
247
+ }
248
+
249
+ /// Labeled Tunnel configuration
250
+ async fn labeled_tunnel(session: &NgrokSession, cfg: &Config) -> Result<String> {
251
+ let mut bld = session.labeled_tunnel();
252
+ plumb!(bld, cfg, metadata);
253
+ plumb_vec!(bld, cfg, label, labels, ":");
254
+ Ok(bld.listen(None).await?.id())
255
+ }
256
+
257
+ /// Set the expected defaults for configuration values
258
+ fn set_defaults(config: &mut Config) {
259
+ if config.proto.is_none() {
260
+ config.proto.replace("http".to_string());
261
+ }
262
+ if config.addr.is_none() {
263
+ if let Some(port) = &config.port {
264
+ config.addr.replace(port.to_string());
265
+ } else if let Some(host) = &config.host {
266
+ config.addr.replace(host.clone());
267
+ } else {
268
+ config.addr.replace("80".to_string());
269
+ }
270
+ }
271
+ }
272
+
273
+ /// Warn about unused configuration values
274
+ fn warn_unused(config: &Config) {
275
+ if config.bin_path.is_some() {
276
+ warn!("bin_path is unused");
277
+ }
278
+ if config.config_path.is_some() {
279
+ warn!("config_path is unused");
280
+ }
281
+ if config.host_header.is_some() {
282
+ warn!("host_header is unused");
283
+ }
284
+ if config.inspect.is_some() {
285
+ warn!("inspect is unused");
286
+ }
287
+ if config.name.is_some() {
288
+ warn!("name is unused");
289
+ }
290
+ if config.region.is_some() {
291
+ warn!("region is unused");
292
+ }
293
+ if let Some(ref schemes) = config.schemes {
294
+ if schemes.len() > 1 {
295
+ warn!("Multiple schemes set, only last one will be used");
296
+ }
297
+ }
298
+ if config.subdomain.is_some() {
299
+ warn!("subdomain is unused");
300
+ }
301
+ if config.terminate_at.is_some() {
302
+ warn!("terminate_at is unused");
303
+ }
304
+ if config.web_addr.is_some() {
305
+ warn!("web_addr is unused");
306
+ }
307
+ }
308
+
309
+ /// Close a tunnel with the given url, or all tunnels if no url is defined.
310
+ #[napi]
311
+ #[allow(dead_code)]
312
+ pub async fn disconnect(url: Option<String>) -> Result<()> {
313
+ tunnel::close_url(url.clone()).await?;
314
+
315
+ // if closing every tunnel, remove any stored session
316
+ if url.as_ref().is_none() {
317
+ SESSION.lock().await.take();
318
+ }
319
+
320
+ Ok(())
321
+ }
322
+
323
+ /// Close all tunnels.
324
+ #[napi]
325
+ #[allow(dead_code)]
326
+ pub async fn kill() -> Result<()> {
327
+ disconnect(None).await
328
+ }
package/src/http.rs CHANGED
@@ -64,28 +64,28 @@ impl NgrokHttpTunnelBuilder {
64
64
  self
65
65
  }
66
66
 
67
- /// with_request_header adds a header to all requests to this edge.
67
+ /// request_header adds a header to all requests to this edge.
68
68
  #[napi]
69
69
  pub fn request_header(&mut self, name: String, value: String) -> &Self {
70
70
  let mut builder = self.tunnel_builder.lock();
71
71
  *builder = builder.clone().request_header(name, value);
72
72
  self
73
73
  }
74
- /// with_response_header adds a header to all responses coming from this edge.
74
+ /// response_header adds a header to all responses coming from this edge.
75
75
  #[napi]
76
76
  pub fn response_header(&mut self, name: String, value: String) -> &Self {
77
77
  let mut builder = self.tunnel_builder.lock();
78
78
  *builder = builder.clone().response_header(name, value);
79
79
  self
80
80
  }
81
- /// with_remove_request_header removes a header from requests to this edge.
81
+ /// remove_request_header removes a header from requests to this edge.
82
82
  #[napi]
83
83
  pub fn remove_request_header(&mut self, name: String) -> &Self {
84
84
  let mut builder = self.tunnel_builder.lock();
85
85
  *builder = builder.clone().remove_request_header(name);
86
86
  self
87
87
  }
88
- /// with_remove_response_header removes a header from responses from this edge.
88
+ /// remove_response_header removes a header from responses from this edge.
89
89
  #[napi]
90
90
  pub fn remove_response_header(&mut self, name: String) -> &Self {
91
91
  let mut builder = self.tunnel_builder.lock();
@@ -104,6 +104,7 @@ impl NgrokHttpTunnelBuilder {
104
104
 
105
105
  /// OAuth configuration.
106
106
  /// If not called, OAuth is disabled.
107
+ /// https://ngrok.com/docs/cloud-edge/modules/oauth/
107
108
  #[napi]
108
109
  pub fn oauth(
109
110
  &mut self,
package/src/lib.rs CHANGED
@@ -3,6 +3,8 @@ use napi::{
3
3
  Status,
4
4
  };
5
5
 
6
+ pub mod config;
7
+ pub mod connect;
6
8
  pub mod http;
7
9
  pub mod logging;
8
10
  pub mod session;