@ngrok/ngrok 0.9.0 → 1.0.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 (146) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/CONTRIBUTING.md +4 -4
  3. package/README.md +176 -142
  4. package/index.d.ts +75 -15
  5. package/index.js +8 -6
  6. package/package.json +37 -16
  7. package/.envrc +0 -1
  8. package/.gitattributes +0 -3
  9. package/.prettierrc.json +0 -3
  10. package/.yarnrc.yml +0 -3
  11. package/Cargo.toml +0 -34
  12. package/RELEASE.md +0 -26
  13. package/build.rs +0 -5
  14. package/docs/.nojekyll +0 -1
  15. package/docs/assets/highlight.css +0 -92
  16. package/docs/assets/main.js +0 -58
  17. package/docs/assets/search.js +0 -1
  18. package/docs/assets/style.css +0 -1367
  19. package/docs/classes/HttpListenerBuilder.html +0 -594
  20. package/docs/classes/LabeledListenerBuilder.html +0 -206
  21. package/docs/classes/Listener.html +0 -241
  22. package/docs/classes/Session.html +0 -207
  23. package/docs/classes/SessionBuilder.html +0 -465
  24. package/docs/classes/TcpListenerBuilder.html +0 -281
  25. package/docs/classes/TlsListenerBuilder.html +0 -322
  26. package/docs/classes/UpdateRequest.html +0 -131
  27. package/docs/functions/authtoken.html +0 -89
  28. package/docs/functions/connect.html +0 -89
  29. package/docs/functions/consoleLog.html +0 -90
  30. package/docs/functions/disconnect.html +0 -89
  31. package/docs/functions/getListener.html +0 -89
  32. package/docs/functions/getListenerByUrl.html +0 -89
  33. package/docs/functions/kill.html +0 -84
  34. package/docs/functions/listen.html +0 -92
  35. package/docs/functions/listenable.html +0 -85
  36. package/docs/functions/listeners.html +0 -84
  37. package/docs/functions/loggingCallback.html +0 -108
  38. package/docs/index.html +0 -292
  39. package/docs/interfaces/Config.html +0 -734
  40. package/docs/modules.html +0 -106
  41. package/examples/domain.crt +0 -18
  42. package/examples/domain.key +0 -27
  43. package/examples/express/ngrok-express-quickstart.js +0 -11
  44. package/examples/express/ngrok-express.js +0 -28
  45. package/examples/express/package.json +0 -7
  46. package/examples/fastify/ngrok-fastify.js +0 -26
  47. package/examples/fastify/package.json +0 -7
  48. package/examples/hapi/ngrok-hapi.js +0 -35
  49. package/examples/hapi/package.json +0 -7
  50. package/examples/koa/ngrok-koa.js +0 -12
  51. package/examples/koa/package.json +0 -7
  52. package/examples/nestjs/.eslintrc.js +0 -25
  53. package/examples/nestjs/.prettierrc +0 -4
  54. package/examples/nestjs/README.md +0 -73
  55. package/examples/nestjs/nest-cli.json +0 -8
  56. package/examples/nestjs/package.json +0 -70
  57. package/examples/nestjs/src/app.controller.spec.ts +0 -22
  58. package/examples/nestjs/src/app.controller.ts +0 -12
  59. package/examples/nestjs/src/app.module.ts +0 -10
  60. package/examples/nestjs/src/app.service.ts +0 -8
  61. package/examples/nestjs/src/main.ts +0 -17
  62. package/examples/nestjs/test/app.e2e-spec.ts +0 -24
  63. package/examples/nestjs/test/jest-e2e.json +0 -9
  64. package/examples/nestjs/tsconfig.build.json +0 -4
  65. package/examples/nestjs/tsconfig.json +0 -21
  66. package/examples/nextjs/README.md +0 -3
  67. package/examples/nextjs/next.config.js +0 -12
  68. package/examples/nextjs/ngrok.config.js +0 -23
  69. package/examples/nextjs/package.json +0 -6
  70. package/examples/nextjs/pages/index.js +0 -5
  71. package/examples/ngrok-connect-full.js +0 -67
  72. package/examples/ngrok-connect-minimal.js +0 -17
  73. package/examples/ngrok-http-full.js +0 -81
  74. package/examples/ngrok-http-minimum.js +0 -18
  75. package/examples/ngrok-labeled.js +0 -43
  76. package/examples/ngrok-listen.js +0 -11
  77. package/examples/ngrok-tcp.js +0 -37
  78. package/examples/ngrok-tls.js +0 -40
  79. package/examples/ngrok-typescript.ts +0 -69
  80. package/examples/ngrok-windows-pipe.js +0 -25
  81. package/examples/ngrok-winston.js +0 -24
  82. package/examples/package.json +0 -15
  83. package/examples/remix/.eslintrc.js +0 -4
  84. package/examples/remix/README.md +0 -53
  85. package/examples/remix/app/entry.client.tsx +0 -18
  86. package/examples/remix/app/entry.server.tsx +0 -101
  87. package/examples/remix/app/root.tsx +0 -20
  88. package/examples/remix/app/routes/_index.tsx +0 -30
  89. package/examples/remix/ngrok.config.js +0 -16
  90. package/examples/remix/package.json +0 -30
  91. package/examples/remix/public/favicon.ico +0 -0
  92. package/examples/remix/remix.config.js +0 -16
  93. package/examples/remix/remix.env.d.ts +0 -2
  94. package/examples/remix/tsconfig.json +0 -22
  95. package/examples/svelte/README.md +0 -38
  96. package/examples/svelte/jsconfig.json +0 -17
  97. package/examples/svelte/ngrok.config.cjs +0 -20
  98. package/examples/svelte/package.json +0 -22
  99. package/examples/svelte/src/app.d.ts +0 -12
  100. package/examples/svelte/src/app.html +0 -12
  101. package/examples/svelte/src/routes/+page.svelte +0 -2
  102. package/examples/svelte/static/favicon.png +0 -0
  103. package/examples/svelte/svelte.config.js +0 -14
  104. package/examples/svelte/vite.config.js +0 -6
  105. package/examples/vue/.vscode/extensions.json +0 -3
  106. package/examples/vue/README.md +0 -40
  107. package/examples/vue/env.d.ts +0 -1
  108. package/examples/vue/index.html +0 -13
  109. package/examples/vue/ngrok.config.ts +0 -18
  110. package/examples/vue/package.json +0 -25
  111. package/examples/vue/public/favicon.ico +0 -0
  112. package/examples/vue/src/App.vue +0 -47
  113. package/examples/vue/src/assets/base.css +0 -74
  114. package/examples/vue/src/assets/logo.svg +0 -1
  115. package/examples/vue/src/assets/main.css +0 -35
  116. package/examples/vue/src/components/HelloWorld.vue +0 -40
  117. package/examples/vue/src/components/TheWelcome.vue +0 -86
  118. package/examples/vue/src/components/WelcomeItem.vue +0 -86
  119. package/examples/vue/src/components/icons/IconCommunity.vue +0 -7
  120. package/examples/vue/src/components/icons/IconDocumentation.vue +0 -7
  121. package/examples/vue/src/components/icons/IconEcosystem.vue +0 -7
  122. package/examples/vue/src/components/icons/IconSupport.vue +0 -7
  123. package/examples/vue/src/components/icons/IconTooling.vue +0 -19
  124. package/examples/vue/src/main.ts +0 -6
  125. package/examples/vue/tsconfig.json +0 -16
  126. package/examples/vue/tsconfig.node.json +0 -8
  127. package/examples/vue/vite.config.ts +0 -15
  128. package/flake.lock +0 -82
  129. package/flake.nix +0 -111
  130. package/post-build.js +0 -45
  131. package/scripts/gc-node-drop.js +0 -49
  132. package/scripts/gc-rust-drop.js +0 -53
  133. package/src/config.rs +0 -285
  134. package/src/connect.rs +0 -342
  135. package/src/http.rs +0 -244
  136. package/src/lib.rs +0 -39
  137. package/src/listener.rs +0 -495
  138. package/src/listener_builder.rs +0 -204
  139. package/src/logging.rs +0 -140
  140. package/src/session.rs +0 -551
  141. package/src/tcp.rs +0 -18
  142. package/src/tls.rs +0 -44
  143. package/trailer.d.ts +0 -15
  144. package/trailer.js +0 -382
  145. package/tsconfig.json +0 -8
  146. package/typedoc.json +0 -3
@@ -1,53 +0,0 @@
1
- // run with: node --trace-gc --expose-gc
2
- if (typeof global.gc !== "function") {
3
- console.log("must run with '--expose-gc'");
4
- process.exit();
5
- }
6
-
7
- const SegfaultHandler = require("../node_modules/segfault-handler");
8
- SegfaultHandler.registerHandler("crash.log");
9
-
10
- const http = require("http");
11
- http
12
- .createServer(function (req, res) {
13
- res.writeHead(200);
14
- res.write("Hello");
15
- res.end();
16
- })
17
- .listen(8081);
18
-
19
- var ngrok = require("..");
20
- // turn on debug
21
- ngrok.consoleLog();
22
-
23
- new ngrok.SessionBuilder()
24
- .authtokenFromEnv()
25
- .connect()
26
- .then((session) => {
27
- session
28
- .httpEndpoint()
29
- .listen()
30
- .then((listener) => {
31
- listener.forward("localhost:8081").await;
32
- const tun_id = listener.id();
33
- console.log("listener: " + listener.url() + " id: " + tun_id);
34
- console.log("\n\n=====> nulling listener");
35
- listener = null; // nodejs can gc
36
-
37
- setTimeout(function () {
38
- console.log("\n\n=====> running gc");
39
- global.gc();
40
- }, 2000);
41
-
42
- setTimeout(function () {
43
- console.log("\n\n=====> closing listener");
44
- session.closeListener(tun_id).await;
45
- }, 4000);
46
-
47
- setTimeout(function () {
48
- console.log("\n\n=====> nulling session, running gc");
49
- session = null;
50
- global.gc();
51
- }, 6000);
52
- });
53
- }).await;
package/src/config.rs DELETED
@@ -1,285 +0,0 @@
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", "unix:/tmp/my.sock", "pipe://./my-pipe"
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
- /// See [Circuit Breaker] in the ngrok docs for additional details.
38
- ///
39
- /// [Circuit Breaker]: https://ngrok.com/docs/cloud-edge/modules/circuit-breaker/
40
- #[napi(js_name = "circuit_breaker")]
41
- pub circuit_breaker: Option<f64>,
42
- /// Enable gzip compression for HTTP responses.
43
- /// See [Compression] in the ngrok docs for additional details.
44
- ///
45
- /// [Compression]: https://ngrok.com/docs/cloud-edge/modules/compression/
46
- pub compression: Option<bool>,
47
- /// Unused, will warn and be ignored
48
- pub config_path: Option<String>,
49
- /// The certificate to use for TLS termination at the ngrok edge in PEM format.
50
- /// Only used if "proto" is "tls".
51
- /// See [TLS Termination] in the ngrok docs for additional details.
52
- ///
53
- /// [TLS Termination]: https://ngrok.com/docs/cloud-edge/modules/tls-termination/
54
- pub crt: Option<String>,
55
- /// The domain to request for this edge, any valid domain or hostname that you have
56
- /// previously registered with ngrok. If using a custom domain, this requires
57
- /// registering in the [ngrok dashboard] and setting a DNS CNAME value.
58
- ///
59
- /// [ngrok dashboard]: https://dashboard.ngrok.com/cloud-edge/domains
60
- pub domain: Option<String>,
61
- /// Returns a human-readable string presented in the ngrok dashboard
62
- /// and the API.
63
- #[napi(js_name = "forwards_to")]
64
- pub forwards_to: Option<String>,
65
- /// Unused, will warn and be ignored
66
- #[napi(js_name = "host_header")]
67
- pub host_header: Option<String>,
68
- /// The hostname for the listener to forward to.
69
- /// Only used if addr is not defined.
70
- pub host: Option<String>,
71
- /// Synonym for domain
72
- pub hostname: Option<String>,
73
- /// Unused, will warn and be ignored
74
- pub inspect: Option<String>,
75
- /// Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
76
- #[napi(
77
- js_name = "ip_restriction_allow_cidrs",
78
- ts_type = "string|Array<string>"
79
- )]
80
- pub allow_cidr: Option<Vec<String>>,
81
- /// Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges.
82
- #[napi(
83
- js_name = "ip_restriction_deny_cidrs",
84
- ts_type = "string|Array<string>"
85
- )]
86
- pub deny_cidr: Option<Vec<String>>,
87
-
88
- /// A set of regular expressions used to match User-Agents that will be allowed.
89
- /// On request, the User Agent Filter module will check the incoming User-Agent header value
90
- /// against the list of defined allow and deny regular expression rules.
91
- /// See `User Agent Filter`_ in the ngrok docs for additional details.
92
- ///
93
- /// .. _User Agent Filter: https://ngrok.com/docs/cloud-edge/modules/user-agent-filter/
94
- #[napi(js_name = "allow_user_agent", ts_type = "string|Array<string>")]
95
- pub allow_user_agent: Option<Vec<String>>,
96
- /// A set of regular expressions used to match User-Agents that will be denied.
97
- /// On request, the User Agent Filter module will check the incoming User-Agent header value
98
- /// against the list of defined allow and deny regular expression rules.
99
- /// See `User Agent Filter`_ in the ngrok docs for additional details.
100
- ///
101
- /// .. _User Agent Filter: https://ngrok.com/docs/cloud-edge/modules/user-agent-filter/
102
- #[napi(js_name = "deny_user_agent", ts_type = "string|Array<string>")]
103
- pub deny_user_agent: Option<Vec<String>>,
104
-
105
- /// The certificate to use for TLS termination at the ngrok edge in PEM format.
106
- /// Only used if "proto" is "tls".
107
- /// See [TLS Termination] in the ngrok docs for additional details.
108
- ///
109
- /// [TLS Termination]: https://ngrok.com/docs/cloud-edge/modules/tls-termination/
110
- pub key: Option<String>,
111
- /// Add label, value pairs for this listener, colon separated.
112
- #[napi(ts_type = "string|Array<string>")]
113
- pub labels: Option<Vec<String>>,
114
- /// Listener-specific opaque metadata. Viewable via the API.
115
- pub metadata: Option<String>,
116
- /// Certificates to use for client authentication at the ngrok edge.
117
- /// Only used if "proto" is "tls" or "http".
118
- /// See [Mutual TLS] in the ngrok docs for additional details.
119
- ///
120
- /// [Mutual TLS]: https://ngrok.com/docs/cloud-edge/modules/mutual-tls/
121
- #[napi(js_name = "mutual_tls_cas", ts_type = "string|Array<string>")]
122
- pub mutual_tls_cas: Option<Vec<String>>,
123
- /// Unused, will warn and be ignored
124
- pub name: Option<String>,
125
-
126
- /// OAuth configuration of domains to allow.
127
- /// See [OAuth] in the ngrok docs for additional details.
128
- ///
129
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
130
- #[napi(js_name = "oauth_allow_domains", ts_type = "string|Array<string>")]
131
- pub oauth_allow_domains: Option<Vec<String>>,
132
- /// OAuth configuration of email addresses to allow.
133
- /// See [OAuth] in the ngrok docs for additional details.
134
- ///
135
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
136
- #[napi(js_name = "oauth_allow_emails", ts_type = "string|Array<string>")]
137
- pub oauth_allow_emails: Option<Vec<String>>,
138
- /// OAuth configuration of scopes.
139
- /// See [OAuth] in the ngrok docs for additional details.
140
- ///
141
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
142
- #[napi(js_name = "oauth_scopes", ts_type = "string|Array<string>")]
143
- pub oauth_scopes: Option<Vec<String>>,
144
- /// OAuth configuration of the provider, e.g. "google".
145
- /// See [OAuth] in the ngrok docs for additional details.
146
- ///
147
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
148
- #[napi(js_name = "oauth_provider")]
149
- pub oauth_provider: Option<String>,
150
- /// OAuth configuration of client ID. Required for scopes.
151
- /// See [OAuth] in the ngrok docs for additional details.
152
- ///
153
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
154
- #[napi(js_name = "oauth_client_id")]
155
- pub oauth_client_id: Option<String>,
156
- /// OAuth configuration of client secret. Required for scopes.
157
- /// See [OAuth] in the ngrok docs for additional details.
158
- ///
159
- /// [OAuth]: https://ngrok.com/docs/cloud-edge/modules/oauth/
160
- #[napi(js_name = "oauth_client_secret")]
161
- pub oauth_client_secret: Option<String>,
162
-
163
- /// OIDC configuration of client ID.
164
- /// See [OpenID Connect] in the ngrok docs for additional details.
165
- ///
166
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
167
- #[napi(js_name = "oidc_client_id")]
168
- pub oidc_client_id: Option<String>,
169
- /// OIDC configuration of client secret.
170
- /// See [OpenID Connect] in the ngrok docs for additional details.
171
- ///
172
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
173
- #[napi(js_name = "oidc_client_secret")]
174
- pub oidc_client_secret: Option<String>,
175
- /// OIDC configuration of scopes.
176
- /// See [OpenID Connect] in the ngrok docs for additional details.
177
- ///
178
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
179
- #[napi(js_name = "oidc_scopes", ts_type = "string|Array<string>")]
180
- pub oidc_scopes: Option<Vec<String>>,
181
- /// OIDC configuration of the issuer URL.
182
- /// See [OpenID Connect] in the ngrok docs for additional details.
183
- ///
184
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
185
- #[napi(js_name = "oidc_issuer_url")]
186
- pub oidc_issuer_url: Option<String>,
187
- /// OIDC configuration of domains to allow.
188
- /// See [OpenID Connect] in the ngrok docs for additional details.
189
- ///
190
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
191
- #[napi(js_name = "oidc_allow_domains", ts_type = "string|Array<string>")]
192
- pub oidc_allow_domains: Option<Vec<String>>,
193
- /// OIDC configuration of email addresses to allow.
194
- /// See [OpenID Connect] in the ngrok docs for additional details.
195
- ///
196
- /// [OpenID Connect]: https://ngrok.com/docs/cloud-edge/modules/openid-connect/
197
- #[napi(js_name = "oidc_allow_emails", ts_type = "string|Array<string>")]
198
- pub oidc_allow_emails: Option<Vec<String>>,
199
-
200
- /// Returns log messages from the ngrok library.
201
- #[napi(ts_type = "(data: string) => void")]
202
- pub on_log_event: Option<bool>,
203
- /// 'closed' - connection is lost, 'connected' - reconnected
204
- #[napi(ts_type = "(status: string) => void")]
205
- pub on_status_change: Option<bool>,
206
- /// The port for the listener to forward to.
207
- /// Only used if addr is not defined.
208
- pub port: Option<u32>,
209
- /// The type of listener to use, one of http|tcp|tls|labeled, defaults to http.
210
- pub proto: Option<String>,
211
- /// The version of PROXY protocol to use with this listener "1", "2", or "" if not using.
212
- #[napi(js_name = "proxy_proto")]
213
- pub proxy_proto: Option<String>,
214
- /// Adds a header to all requests to this edge.
215
- /// See [Request Headers] in the ngrok docs for additional details.
216
- ///
217
- /// [Request Headers]: https://ngrok.com/docs/cloud-edge/modules/request-headers/
218
- #[napi(js_name = "request_header_add", ts_type = "string|Array<string>")]
219
- pub request_header_add: Option<Vec<String>>,
220
- /// Removes a header from requests to this edge.
221
- /// See [Request Headers] in the ngrok docs for additional details.
222
- ///
223
- /// [Request Headers]: https://ngrok.com/docs/cloud-edge/modules/request-headers/
224
- #[napi(js_name = "request_header_remove", ts_type = "string|Array<string>")]
225
- pub request_header_remove: Option<Vec<String>>,
226
- /// Adds a header to all responses coming from this edge.
227
- /// See [Response Headers] in the ngrok docs for additional details.
228
- ///
229
- /// [Response Headers]: https://ngrok.com/docs/cloud-edge/modules/response-headers/
230
- #[napi(js_name = "response_header_add", ts_type = "string|Array<string>")]
231
- pub response_header_add: Option<Vec<String>>,
232
- /// Removes a header from responses from this edge.
233
- /// See [Response Headers] in the ngrok docs for additional details.
234
- ///
235
- /// [Response Headers]: https://ngrok.com/docs/cloud-edge/modules/response-headers/
236
- #[napi(js_name = "response_header_remove", ts_type = "string|Array<string>")]
237
- pub response_header_remove: Option<Vec<String>>,
238
- /// Unused, will warn and be ignored
239
- pub region: Option<String>,
240
- /// The TCP address to request for this edge.
241
- /// These addresses can be reserved in the [ngrok dashboard] to use across sessions. For example: remote_addr("2.tcp.ngrok.io:21746")
242
- /// Only used if proto is "tcp".
243
- ///
244
- /// [ngrok dashboard]: https://dashboard.ngrok.com/cloud-edge/tcp-addresses
245
- #[napi(js_name = "remote_addr")]
246
- pub remote_addr: Option<String>,
247
- /// The scheme that this edge should use.
248
- /// "HTTPS" or "HTTP", defaults to "HTTPS".
249
- /// If multiple are given only the last one is used.
250
- #[napi(ts_type = "string|Array<string>")]
251
- pub schemes: Option<Vec<String>>,
252
- /// Configures the opaque, machine-readable metadata string for this session.
253
- /// Metadata is made available to you in the ngrok dashboard and the Agents API
254
- /// resource. It is a useful way to allow you to uniquely identify sessions. We
255
- /// suggest encoding the value in a structured format like JSON.
256
- ///
257
- /// See the [metdata parameter in the ngrok docs] for additional details.
258
- ///
259
- /// [metdata parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#metadata
260
- #[napi(js_name = "session_metadata")]
261
- pub session_metadata: Option<String>,
262
- /// Unused, use domain instead, will warn and be ignored
263
- pub subdomain: Option<String>,
264
- /// Unused, will warn and be ignored
265
- #[napi(js_name = "terminate_at")]
266
- pub terminate_at: Option<String>,
267
- /// WebhookVerification configuration, the provider to use.
268
- /// See [Webhook Verification] in the ngrok docs for additional details.
269
- ///
270
- /// [Webhook Verification]: https://ngrok.com/docs/cloud-edge/modules/webhook-verification/
271
- #[napi(js_name = "verify_webhook_provider")]
272
- pub verify_webhook_provider: Option<String>,
273
- /// WebhookVerification configuration, the secret to use.
274
- /// See [Webhook Verification] in the ngrok docs for additional details.
275
- ///
276
- /// [Webhook Verification]: https://ngrok.com/docs/cloud-edge/modules/webhook-verification/
277
- #[napi(js_name = "verify_webhook_secret")]
278
- pub verify_webhook_secret: Option<String>,
279
- /// Unused, will warn and be ignored
280
- #[napi(js_name = "web_addr")]
281
- pub web_addr: Option<String>,
282
- /// Convert incoming websocket connections to TCP-like streams.
283
- #[napi(js_name = "websocket_tcp_converter")]
284
- pub websocket_tcp_converter: Option<bool>,
285
- }
package/src/connect.rs DELETED
@@ -1,342 +0,0 @@
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
- listener::{
13
- self,
14
- Listener,
15
- TCP_PREFIX,
16
- },
17
- logging::logging_callback,
18
- napi_err,
19
- session::{
20
- Session,
21
- SessionBuilder,
22
- },
23
- };
24
-
25
- lazy_static! {
26
- // Save a user-facing NgrokSession to use for connect use cases
27
- pub(crate) static ref SESSION: Mutex<Option<Session>> = Mutex::new(None);
28
- }
29
-
30
- /// Single string configuration
31
- macro_rules! plumb {
32
- ($builder:tt, $config:tt, $name:tt) => {
33
- plumb!($builder, $config, $name, $name)
34
- };
35
- ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
36
- if let Some(ref $name) = $config.$config_name {
37
- $builder.$name($name.clone());
38
- }
39
- };
40
- }
41
-
42
- /// Boolean configuration
43
- macro_rules! plumb_bool {
44
- ($builder:tt, $config:tt, $name:tt) => {
45
- plumb_bool!($builder, $config, $name, $name)
46
- };
47
- ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
48
- if let Some($name) = $config.$config_name {
49
- if $name {
50
- $builder.$name();
51
- }
52
- }
53
- };
54
- }
55
-
56
- /// Vector configuration
57
- macro_rules! plumb_vec {
58
- ($builder:tt, $config:tt, $name:tt) => {
59
- plumb_vec!($builder, $config, $name, $name)
60
- };
61
- ($builder:tt, $config:tt, $name:tt, $config_name:tt) => {
62
- if let Some(ref $name) = $config.$config_name {
63
- for val in $name {
64
- $builder.$name(val.clone());
65
- }
66
- }
67
- };
68
- ($builder:tt, $config:tt, $name:tt, $config_name:tt, vecu8) => {
69
- if let Some(ref $name) = $config.$config_name {
70
- for val in $name {
71
- $builder.$name(Uint8Array::new(val.as_bytes().to_vec()));
72
- }
73
- }
74
- };
75
- ($builder:tt, $config:tt, $name:tt, $config_name:tt, $split:tt) => {
76
- if let Some(ref $name) = $config.$config_name {
77
- for val in $name {
78
- let (a, b) = val
79
- .split_once($split)
80
- .expect("split of value failed: ${val}");
81
- $builder.$name(a.to_string(), b.to_string());
82
- }
83
- }
84
- };
85
- }
86
-
87
- /// All non-labeled listeners have these common configuration options
88
- macro_rules! config_common {
89
- ($builder:tt, $config:tt) => {
90
- plumb!($builder, $config, metadata);
91
- plumb_vec!($builder, $config, allow_cidr);
92
- plumb_vec!($builder, $config, deny_cidr);
93
- plumb!($builder, $config, proxy_proto);
94
- plumb!($builder, $config, forwards_to);
95
- };
96
- }
97
-
98
- /// Transform a json object configuration into a listener
99
- #[napi(
100
- ts_args_type = "config: Config|string|number",
101
- ts_return_type = "Promise<Listener>"
102
- )]
103
- #[allow(dead_code)]
104
- pub fn connect(
105
- env: Env,
106
- mut cfg: Config,
107
- on_log_event: Option<JsFunction>,
108
- on_connection: Option<JsFunction>,
109
- on_disconnection: Option<JsFunction>,
110
- ) -> Result<JsObject> {
111
- // do logging configuration before anything else
112
- if on_log_event.is_some() {
113
- logging_callback(env, on_log_event, None)?;
114
- }
115
- warn_unused(&cfg);
116
- set_defaults(&mut cfg);
117
-
118
- // session configuration
119
- let mut s_builder = SessionBuilder::new();
120
- plumb!(s_builder, cfg, authtoken);
121
- plumb_bool!(s_builder, cfg, authtoken_from_env);
122
- plumb!(s_builder, cfg, metadata, session_metadata);
123
- if let Some(func) = on_connection {
124
- s_builder.handle_connection(env, func);
125
- }
126
- if let Some(func) = on_disconnection {
127
- s_builder.handle_disconnection(env, func);
128
- }
129
-
130
- // no longer need Env, hand off to async for listener creation, returning the promise to nodejs.
131
- env.spawn_future(async_connect(s_builder, cfg))
132
- }
133
-
134
- /// Connect the session, configure and start the listener
135
- async fn async_connect(s_builder: SessionBuilder, config: Config) -> Result<Listener> {
136
- // Using a singleton session for connect use cases
137
- let mut opt = SESSION.lock().await;
138
- if opt.is_none() {
139
- opt.replace(s_builder.connect().await?);
140
- }
141
- let session = opt.as_ref().unwrap();
142
-
143
- // listener configuration dispatch
144
- let proto = config.proto.as_ref().unwrap();
145
- let id = match proto.as_str() {
146
- "http" => http_endpoint(session, &config).await?,
147
- "tcp" => tcp_endpoint(session, &config).await?,
148
- "tls" => tls_endpoint(session, &config).await?,
149
- "labeled" => labeled_listener(session, &config).await?,
150
- _ => return Err(napi_err(format!("unhandled protocol {proto}"))),
151
- };
152
-
153
- let listener = listener::get_listener(id.clone())
154
- .await
155
- .ok_or(napi_err("failed to start listener".to_string()))?;
156
-
157
- // move forwarding to another task
158
- if let Some(addr) = config.addr {
159
- tokio::spawn(async move { listener::forward(&id, addr).await });
160
- }
161
-
162
- Ok(listener)
163
- }
164
-
165
- /// HTTP Listener configuration
166
- async fn http_endpoint(session: &Session, 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
- plumb_vec!(bld, cfg, allow_user_agent, allow_user_agent);
181
- plumb_vec!(bld, cfg, deny_user_agent, deny_user_agent);
182
- // circuit breaker
183
- if let Some(circuit_breaker) = cfg.circuit_breaker {
184
- bld.circuit_breaker(circuit_breaker);
185
- }
186
- // oauth
187
- if let Some(ref provider) = cfg.oauth_provider {
188
- bld.oauth(
189
- provider.clone(),
190
- cfg.oauth_allow_emails.clone(),
191
- cfg.oauth_allow_domains.clone(),
192
- cfg.oauth_scopes.clone(),
193
- cfg.oauth_client_id.clone(),
194
- cfg.oauth_client_secret.clone(),
195
- );
196
- }
197
- // oidc
198
- if let Some(ref issuer_url) = cfg.oidc_issuer_url {
199
- if cfg.oidc_client_id.is_none() {
200
- return Err(napi_err("Missing client id for oidc"));
201
- }
202
- if cfg.oidc_client_secret.is_none() {
203
- return Err(napi_err("Missing client secret for oidc"));
204
- }
205
- bld.oidc(
206
- issuer_url.clone(),
207
- cfg.oidc_client_id.clone().unwrap(),
208
- cfg.oidc_client_secret.clone().unwrap(),
209
- cfg.oidc_allow_emails.clone(),
210
- cfg.oidc_allow_domains.clone(),
211
- cfg.oidc_scopes.clone(),
212
- );
213
- }
214
- // webhook verification
215
- if let Some(ref provider) = cfg.verify_webhook_provider {
216
- if let Some(ref secret) = cfg.verify_webhook_secret {
217
- bld.webhook_verification(provider.clone(), secret.clone());
218
- } else {
219
- return Err(napi_err("Missing secret for webhook verification"));
220
- }
221
- }
222
- Ok(bld.listen(None).await?.id())
223
- }
224
-
225
- /// TCP Listener configuration
226
- async fn tcp_endpoint(session: &Session, cfg: &Config) -> Result<String> {
227
- let mut bld = session.tcp_endpoint();
228
- config_common!(bld, cfg);
229
- plumb!(bld, cfg, remote_addr);
230
- Ok(bld.listen(None).await?.id())
231
- }
232
-
233
- /// TLS Listener configuration
234
- async fn tls_endpoint(session: &Session, cfg: &Config) -> Result<String> {
235
- let mut bld = session.tls_endpoint();
236
- config_common!(bld, cfg);
237
- plumb!(bld, cfg, domain, hostname); // synonym for domain
238
- plumb!(bld, cfg, domain);
239
- plumb_vec!(bld, cfg, mutual_tlsca, mutual_tls_cas, vecu8);
240
- if let Some(ref crt) = cfg.crt {
241
- if let Some(ref key) = cfg.key {
242
- bld.termination(
243
- Uint8Array::new(crt.as_bytes().to_vec()),
244
- Uint8Array::new(key.as_bytes().to_vec()),
245
- );
246
- } else {
247
- return Err(napi_err("Missing key for tls termination"));
248
- }
249
- }
250
- Ok(bld.listen(None).await?.id())
251
- }
252
-
253
- /// Labeled Listener configuration
254
- async fn labeled_listener(session: &Session, cfg: &Config) -> Result<String> {
255
- let mut bld = session.labeled_listener();
256
- plumb!(bld, cfg, metadata);
257
- plumb_vec!(bld, cfg, label, labels, ":");
258
- Ok(bld.listen(None).await?.id())
259
- }
260
-
261
- /// Set the expected defaults for configuration values
262
- fn set_defaults(config: &mut Config) {
263
- if config.proto.is_none() {
264
- config.proto.replace("http".to_string());
265
- }
266
- if config.addr.is_none() {
267
- if let Some(port) = &config.port {
268
- if let Some(host) = &config.host {
269
- config.addr.replace(format!("{TCP_PREFIX}{host}:{port}"));
270
- } else {
271
- config.addr.replace(format!("{TCP_PREFIX}localhost:{port}"));
272
- }
273
- } else if let Some(host) = &config.host {
274
- config.addr.replace(host.clone());
275
- } else {
276
- config.addr.replace("80".to_string());
277
- }
278
- }
279
- if let Some(addr) = &config.addr {
280
- if addr.parse::<i32>().is_ok() {
281
- // the string is a number, interpret it as a port
282
- config.addr.replace(format!("{TCP_PREFIX}localhost:{addr}"));
283
- }
284
- }
285
- }
286
-
287
- /// Warn about unused configuration values
288
- fn warn_unused(config: &Config) {
289
- if config.bin_path.is_some() {
290
- warn!("bin_path is unused");
291
- }
292
- if config.config_path.is_some() {
293
- warn!("config_path is unused");
294
- }
295
- if config.host_header.is_some() {
296
- warn!("host_header is unused");
297
- }
298
- if config.inspect.is_some() {
299
- warn!("inspect is unused");
300
- }
301
- if config.name.is_some() {
302
- warn!("name is unused");
303
- }
304
- if config.region.is_some() {
305
- warn!("region is unused");
306
- }
307
- if let Some(ref schemes) = config.schemes {
308
- if schemes.len() > 1 {
309
- warn!("Multiple schemes set, only last one will be used");
310
- }
311
- }
312
- if config.subdomain.is_some() {
313
- warn!("subdomain is unused");
314
- }
315
- if config.terminate_at.is_some() {
316
- warn!("terminate_at is unused");
317
- }
318
- if config.web_addr.is_some() {
319
- warn!("web_addr is unused");
320
- }
321
- }
322
-
323
- /// Close a listener with the given url, or all listeners if no url is defined.
324
- #[napi]
325
- #[allow(dead_code)]
326
- pub async fn disconnect(url: Option<String>) -> Result<()> {
327
- listener::close_url(url.clone()).await?;
328
-
329
- // if closing every listener, remove any stored session
330
- if url.as_ref().is_none() {
331
- SESSION.lock().await.take();
332
- }
333
-
334
- Ok(())
335
- }
336
-
337
- /// Close all listeners.
338
- #[napi]
339
- #[allow(dead_code)]
340
- pub async fn kill() -> Result<()> {
341
- disconnect(None).await
342
- }