@ngrok/ngrok 0.1.1 → 0.3.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/.prettierrc.json +3 -0
- package/CHANGELOG.md +10 -0
- package/Cargo.toml +1 -1
- package/README.md +51 -10
- package/RELEASE.md +3 -3
- package/docs/assets/highlight.css +13 -6
- package/docs/assets/main.js +3 -3
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +447 -362
- package/docs/classes/NgrokHttpTunnel.html +112 -77
- package/docs/classes/NgrokHttpTunnelBuilder.html +235 -199
- package/docs/classes/NgrokLabeledTunnel.html +107 -72
- package/docs/classes/NgrokLabeledTunnelBuilder.html +84 -49
- package/docs/classes/NgrokSession.html +99 -66
- package/docs/classes/NgrokSessionBuilder.html +171 -138
- package/docs/classes/NgrokTcpTunnel.html +112 -77
- package/docs/classes/NgrokTcpTunnelBuilder.html +115 -80
- package/docs/classes/NgrokTlsTunnel.html +112 -77
- package/docs/classes/NgrokTlsTunnelBuilder.html +133 -98
- package/docs/classes/UpdateRequest.html +69 -33
- package/docs/functions/authtoken.html +88 -0
- package/docs/functions/connect.html +88 -0
- package/docs/functions/consoleLog.html +50 -34
- package/docs/functions/disconnect.html +88 -0
- package/docs/functions/kill.html +83 -0
- package/docs/functions/listen.html +52 -36
- package/docs/functions/listenable.html +51 -35
- package/docs/functions/loggingCallback.html +56 -40
- package/docs/index.html +115 -84
- package/docs/interfaces/Config.html +608 -0
- package/docs/modules.html +74 -47
- package/examples/express/ngrok-express-quickstart.js +11 -0
- package/examples/express/ngrok-express.js +28 -0
- package/examples/express/package.json +7 -0
- package/examples/fastify/ngrok-fastify.js +26 -0
- package/examples/fastify/package.json +7 -0
- package/examples/hapi/ngrok-hapi.js +35 -0
- package/examples/hapi/package.json +7 -0
- package/examples/koa/ngrok-koa.js +12 -0
- package/examples/koa/package.json +7 -0
- package/examples/nestjs/.eslintrc.js +25 -0
- package/examples/nestjs/.prettierrc +4 -0
- package/examples/nestjs/README.md +73 -0
- package/examples/nestjs/nest-cli.json +8 -0
- package/examples/nestjs/package-lock.json +12138 -0
- package/examples/nestjs/package.json +70 -0
- package/examples/nestjs/src/app.controller.spec.ts +22 -0
- package/examples/nestjs/src/app.controller.ts +12 -0
- package/examples/nestjs/src/app.module.ts +10 -0
- package/examples/nestjs/src/app.service.ts +8 -0
- package/examples/nestjs/src/main.ts +17 -0
- package/examples/nestjs/test/app.e2e-spec.ts +24 -0
- package/examples/nestjs/test/jest-e2e.json +9 -0
- package/examples/nestjs/tsconfig.build.json +4 -0
- package/examples/nestjs/tsconfig.json +21 -0
- package/examples/nextjs/next.config.js +12 -0
- package/examples/nextjs/ngrok.config.js +23 -0
- package/examples/nextjs/package.json +6 -0
- package/examples/nextjs/pages/index.js +5 -0
- package/examples/ngrok-connect-full.js +64 -0
- package/examples/ngrok-connect-minimal.js +16 -0
- package/examples/ngrok-http-full.js +28 -22
- package/examples/ngrok-http-minimum.js +17 -13
- package/examples/ngrok-labeled.js +22 -18
- package/examples/ngrok-listen.js +6 -7
- package/examples/ngrok-tcp.js +22 -19
- package/examples/ngrok-tls.js +23 -20
- package/examples/ngrok-typescript.ts +32 -27
- package/examples/ngrok-windows-pipe.js +22 -14
- package/examples/ngrok-winston.js +9 -9
- package/examples/package.json +11 -0
- package/examples/remix/.eslintrc.js +4 -0
- package/examples/remix/README.md +53 -0
- package/examples/remix/app/entry.client.tsx +18 -0
- package/examples/remix/app/entry.server.tsx +101 -0
- package/examples/remix/app/root.tsx +20 -0
- package/examples/remix/app/routes/_index.tsx +30 -0
- package/examples/remix/ngrok.config.js +16 -0
- package/examples/remix/package.json +30 -0
- package/examples/remix/public/favicon.ico +0 -0
- package/examples/remix/remix.config.js +16 -0
- package/examples/remix/remix.env.d.ts +2 -0
- package/examples/remix/tsconfig.json +22 -0
- package/examples/svelte/README.md +38 -0
- package/examples/svelte/jsconfig.json +17 -0
- package/examples/svelte/ngrok.config.cjs +18 -0
- package/examples/svelte/package.json +22 -0
- package/examples/svelte/src/app.d.ts +12 -0
- package/examples/svelte/src/app.html +12 -0
- package/examples/svelte/src/routes/+page.svelte +2 -0
- package/examples/svelte/static/favicon.png +0 -0
- package/examples/svelte/svelte.config.js +14 -0
- package/examples/svelte/vite.config.js +6 -0
- package/examples/vue/.vscode/extensions.json +3 -0
- package/examples/vue/README.md +40 -0
- package/examples/vue/env.d.ts +1 -0
- package/examples/vue/index.html +13 -0
- package/examples/vue/ngrok.config.ts +18 -0
- package/examples/vue/package.json +25 -0
- package/examples/vue/public/favicon.ico +0 -0
- package/examples/vue/src/App.vue +47 -0
- package/examples/vue/src/assets/base.css +74 -0
- package/examples/vue/src/assets/logo.svg +1 -0
- package/examples/vue/src/assets/main.css +35 -0
- package/examples/vue/src/components/HelloWorld.vue +40 -0
- package/examples/vue/src/components/TheWelcome.vue +86 -0
- package/examples/vue/src/components/WelcomeItem.vue +86 -0
- package/examples/vue/src/components/icons/IconCommunity.vue +7 -0
- package/examples/vue/src/components/icons/IconDocumentation.vue +7 -0
- package/examples/vue/src/components/icons/IconEcosystem.vue +7 -0
- package/examples/vue/src/components/icons/IconSupport.vue +7 -0
- package/examples/vue/src/components/icons/IconTooling.vue +19 -0
- package/examples/vue/src/main.ts +6 -0
- package/examples/vue/tsconfig.json +16 -0
- package/examples/vue/tsconfig.node.json +8 -0
- package/examples/vue/vite.config.ts +15 -0
- package/flake.nix +1 -1
- package/index.d.ts +243 -19
- package/index.js +145 -29
- package/package.json +20 -21
- package/post-build.js +18 -11
- package/scripts/gc-node-drop.js +38 -31
- package/scripts/gc-rust-drop.js +44 -38
- package/src/config.rs +182 -0
- package/src/connect.rs +328 -0
- package/src/http.rs +5 -4
- package/src/lib.rs +2 -0
- package/src/session.rs +61 -4
- package/src/tls.rs +1 -1
- package/src/tunnel.rs +105 -37
- package/src/tunnel_builder.rs +8 -0
- package/trailer.d.ts +9 -4
- package/trailer.js +140 -28
- package/examples/ngrok-express-quickstart.js +0 -11
- package/examples/ngrok-express.js +0 -26
package/index.d.ts
CHANGED
|
@@ -3,13 +3,190 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Configuration object to pass to ngrok.connect()
|
|
8
|
+
*
|
|
9
|
+
* @group Functions
|
|
10
|
+
*/
|
|
11
|
+
export interface Config {
|
|
12
|
+
/**
|
|
13
|
+
* Port, network address, or named pipe. Defaults to 80.
|
|
14
|
+
* Examples: "80", "localhost:8080", "pipe:/tmp/my.sock"
|
|
15
|
+
*/
|
|
16
|
+
addr?: number|string
|
|
17
|
+
auth?: string|Array<string>
|
|
18
|
+
/**
|
|
19
|
+
* Configures the session to authenticate with the provided authtoken. You
|
|
20
|
+
* can [find your existing authtoken] or [create a new one] in the ngrok
|
|
21
|
+
* dashboard.
|
|
22
|
+
*
|
|
23
|
+
* See the [authtoken parameter in the ngrok docs] for additional details.
|
|
24
|
+
*
|
|
25
|
+
* [find your existing authtoken]: https://dashboard.ngrok.com/get-started/your-authtoken
|
|
26
|
+
* [create a new one]: https://dashboard.ngrok.com/tunnels/authtokens
|
|
27
|
+
* [authtoken parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#authtoken
|
|
28
|
+
*/
|
|
29
|
+
authtoken?: string
|
|
30
|
+
/**
|
|
31
|
+
* Shortcut for calling [SessionBuilder::authtoken] with the value of the
|
|
32
|
+
* NGROK_AUTHTOKEN environment variable.
|
|
33
|
+
*/
|
|
34
|
+
authtoken_from_env?: boolean
|
|
35
|
+
/** Credentials for basic authentication, with username and password colon separated. */
|
|
36
|
+
basic_auth?: string|Array<string>
|
|
37
|
+
/** Unused, will warn and be ignored */
|
|
38
|
+
binPath?: string
|
|
39
|
+
/**
|
|
40
|
+
* Reject requests when 5XX responses exceed this ratio.
|
|
41
|
+
* Disabled when 0.
|
|
42
|
+
*/
|
|
43
|
+
circuit_breaker?: number
|
|
44
|
+
/** Enable gzip compression for HTTP responses. */
|
|
45
|
+
compression?: boolean
|
|
46
|
+
/** Unused, will warn and be ignored */
|
|
47
|
+
configPath?: string
|
|
48
|
+
/**
|
|
49
|
+
* The certificate to use for TLS termination at the ngrok edge in PEM format.
|
|
50
|
+
* Only used if "proto" is "tls".
|
|
51
|
+
*/
|
|
52
|
+
crt?: string
|
|
53
|
+
/** The domain to request for this edge. */
|
|
54
|
+
domain?: string
|
|
55
|
+
/**
|
|
56
|
+
* Returns a human-readable string presented in the ngrok dashboard
|
|
57
|
+
* and the Tunnels API.
|
|
58
|
+
*/
|
|
59
|
+
forwards_to?: string
|
|
60
|
+
/** Unused, will warn and be ignored */
|
|
61
|
+
host_header?: string
|
|
62
|
+
/**
|
|
63
|
+
* The hostname for the tunnel to forward to.
|
|
64
|
+
* Only used if addr is not defined.
|
|
65
|
+
*/
|
|
66
|
+
host?: string
|
|
67
|
+
/** Synonym for domain */
|
|
68
|
+
hostname?: string
|
|
69
|
+
/** Unused, will warn and be ignored */
|
|
70
|
+
inspect?: string
|
|
71
|
+
/** Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges. */
|
|
72
|
+
ip_restriction_allow_cidrs?: string|Array<string>
|
|
73
|
+
/** Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges. */
|
|
74
|
+
ip_restriction_deny_cidrs?: string|Array<string>
|
|
75
|
+
/**
|
|
76
|
+
* The certificate to use for TLS termination at the ngrok edge in PEM format.
|
|
77
|
+
* Only used if "proto" is "tls".
|
|
78
|
+
*/
|
|
79
|
+
key?: string
|
|
80
|
+
/** Add label, value pairs for this tunnel, colon separated. */
|
|
81
|
+
labels?: string|Array<string>
|
|
82
|
+
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
83
|
+
metadata?: string
|
|
84
|
+
/**
|
|
85
|
+
* Certificates to use for client authentication at the ngrok edge.
|
|
86
|
+
* Only used if "proto" is "tls" or "http".
|
|
87
|
+
*/
|
|
88
|
+
mutual_tls_cas?: string|Array<string>
|
|
89
|
+
/** Unused, will warn and be ignored */
|
|
90
|
+
name?: string
|
|
91
|
+
/** OAuth configuration of domains to allow. */
|
|
92
|
+
oauth_allow_domains?: string|Array<string>
|
|
93
|
+
/** OAuth configuration of email addresses to allow. */
|
|
94
|
+
oauth_allow_emails?: string|Array<string>
|
|
95
|
+
/** OAuth configuration of scopes. */
|
|
96
|
+
oauth_scopes?: string|Array<string>
|
|
97
|
+
/**
|
|
98
|
+
* OAuth configuration of the provider, e.g. "google".
|
|
99
|
+
* https://ngrok.com/docs/cloud-edge/modules/oauth/
|
|
100
|
+
*/
|
|
101
|
+
oauth_provider?: string
|
|
102
|
+
/** OIDC configuration of client ID. */
|
|
103
|
+
oidc_client_id?: string
|
|
104
|
+
/** OIDC configuration of client secret. */
|
|
105
|
+
oidc_client_secret?: string
|
|
106
|
+
/** OIDC configuration of scopes. */
|
|
107
|
+
oidc_scopes?: string|Array<string>
|
|
108
|
+
/** OIDC configuration of the issuer URL. */
|
|
109
|
+
oidc_issuer_url?: string
|
|
110
|
+
/** OIDC configuration of domains to allow. */
|
|
111
|
+
oidc_allow_domains?: string|Array<string>
|
|
112
|
+
/** OIDC configuration of email addresses to allow. */
|
|
113
|
+
oidc_allow_emails?: string|Array<string>
|
|
114
|
+
/** Returns log messages from the ngrok library. */
|
|
115
|
+
onLogEvent?: (data: string) => void
|
|
116
|
+
/** 'closed' - connection is lost, 'connected' - reconnected */
|
|
117
|
+
onStatusChange?: (status: string) => void
|
|
118
|
+
/**
|
|
119
|
+
* The port for the tunnel to forward to.
|
|
120
|
+
* Only used if addr is not defined.
|
|
121
|
+
*/
|
|
122
|
+
port?: number
|
|
123
|
+
/** The type of tunnel to use, one of http|tcp|tls|labeled, defaults to http. */
|
|
124
|
+
proto?: string
|
|
125
|
+
/** The version of PROXY protocol to use with this tunnel "1", "2", or "" if not using. */
|
|
126
|
+
proxy_proto?: string
|
|
127
|
+
/** Adds a header to all requests to this edge. */
|
|
128
|
+
request_header_add?: string|Array<string>
|
|
129
|
+
/** Removes a header from requests to this edge. */
|
|
130
|
+
request_header_remove?: string|Array<string>
|
|
131
|
+
/** Adds a header to all responses coming from this edge. */
|
|
132
|
+
response_header_add?: string|Array<string>
|
|
133
|
+
/** Removes a header from responses from this edge. */
|
|
134
|
+
response_header_remove?: string|Array<string>
|
|
135
|
+
/** Unused, will warn and be ignored */
|
|
136
|
+
region?: string
|
|
137
|
+
/**
|
|
138
|
+
* The TCP address to request for this edge.
|
|
139
|
+
* Only used if proto is "tcp".
|
|
140
|
+
*/
|
|
141
|
+
remote_addr?: string
|
|
142
|
+
/**
|
|
143
|
+
* The scheme that this edge should use, defaults to "https".
|
|
144
|
+
* If multiple are given only the last one is used.
|
|
145
|
+
*/
|
|
146
|
+
schemes?: string|Array<string>
|
|
147
|
+
/**
|
|
148
|
+
* Configures the opaque, machine-readable metadata string for this session.
|
|
149
|
+
* Metadata is made available to you in the ngrok dashboard and the Agents API
|
|
150
|
+
* resource. It is a useful way to allow you to uniquely identify sessions. We
|
|
151
|
+
* suggest encoding the value in a structured format like JSON.
|
|
152
|
+
*
|
|
153
|
+
* See the [metdata parameter in the ngrok docs] for additional details.
|
|
154
|
+
*
|
|
155
|
+
* [metdata parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#metadata
|
|
156
|
+
*/
|
|
157
|
+
session_metadata?: string
|
|
158
|
+
/** Unused, use domain instead, will warn and be ignored */
|
|
159
|
+
subdomain?: string
|
|
160
|
+
/** Unused, will warn and be ignored */
|
|
161
|
+
terminate_at?: string
|
|
162
|
+
/** WebhookVerification configuration, the provider to use. */
|
|
163
|
+
verify_webhook_provider?: string
|
|
164
|
+
/** WebhookVerification configuration, the secret to use. */
|
|
165
|
+
verify_webhook_secret?: string
|
|
166
|
+
/** Unused, will warn and be ignored */
|
|
167
|
+
web_addr?: string
|
|
168
|
+
/** Convert incoming websocket connections to TCP-like streams. */
|
|
169
|
+
websocket_tcp_converter?: boolean
|
|
170
|
+
}
|
|
171
|
+
/** Transform a json object configuration into a tunnel */
|
|
172
|
+
export function connect(config: Config|string|number): Promise<string>
|
|
173
|
+
/** Close a tunnel with the given url, or all tunnels if no url is defined. */
|
|
174
|
+
export function disconnect(url?: string | undefined | null): Promise<void>
|
|
175
|
+
/** Close all tunnels. */
|
|
176
|
+
export function kill(): Promise<void>
|
|
6
177
|
/**
|
|
7
178
|
* Register a callback function that will receive logging event information.
|
|
8
179
|
* An absent callback will unregister an existing callback function.
|
|
9
180
|
* The log level defaults to INFO, it can be set to one of ERROR, WARN, INFO, DEBUG, or TRACE.
|
|
10
181
|
*/
|
|
11
182
|
export function loggingCallback(callback?: (level: string, target: string, message: string) => void, level?: string): void
|
|
12
|
-
/**
|
|
183
|
+
/** Set the default auth token to use for any future sessions. */
|
|
184
|
+
export function authtoken(authtoken: string): Promise<void>
|
|
185
|
+
/**
|
|
186
|
+
* The builder for an ngrok session.
|
|
187
|
+
*
|
|
188
|
+
* @group Sessions
|
|
189
|
+
*/
|
|
13
190
|
export class NgrokSessionBuilder {
|
|
14
191
|
/** Create a new session builder */
|
|
15
192
|
constructor()
|
|
@@ -143,7 +320,11 @@ export class NgrokSessionBuilder {
|
|
|
143
320
|
/** Attempt to establish an ngrok session using the current configuration. */
|
|
144
321
|
connect(): Promise<NgrokSession>
|
|
145
322
|
}
|
|
146
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* An ngrok session.
|
|
325
|
+
*
|
|
326
|
+
* @group Sessions
|
|
327
|
+
*/
|
|
147
328
|
export class NgrokSession {
|
|
148
329
|
/** Start building a tunnel backing an HTTP endpoint. */
|
|
149
330
|
httpEndpoint(): NgrokHttpTunnelBuilder
|
|
@@ -158,13 +339,22 @@ export class NgrokSession {
|
|
|
158
339
|
/** Close the ngrok session. */
|
|
159
340
|
close(): Promise<void>
|
|
160
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Container for UpdateRequest information.
|
|
344
|
+
*
|
|
345
|
+
* @group Sessions
|
|
346
|
+
*/
|
|
161
347
|
export class UpdateRequest {
|
|
162
348
|
/** The version that the agent is requested to update to. */
|
|
163
349
|
version: string
|
|
164
350
|
/** Whether or not updating to the same major version is sufficient. */
|
|
165
351
|
permitMajorVersion: boolean
|
|
166
352
|
}
|
|
167
|
-
/**
|
|
353
|
+
/**
|
|
354
|
+
*r" An ngrok tunnel backing an HTTP endpoint.
|
|
355
|
+
*r"
|
|
356
|
+
*r" @group Tunnels
|
|
357
|
+
*/
|
|
168
358
|
export class NgrokHttpTunnel {
|
|
169
359
|
/** The URL that this tunnel backs. */
|
|
170
360
|
url(): string
|
|
@@ -198,7 +388,11 @@ export class NgrokHttpTunnel {
|
|
|
198
388
|
*/
|
|
199
389
|
close(): Promise<void>
|
|
200
390
|
}
|
|
201
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
*r" An ngrok tunnel backing a TCP endpoint.
|
|
393
|
+
*r"
|
|
394
|
+
*r" @group Tunnels
|
|
395
|
+
*/
|
|
202
396
|
export class NgrokTcpTunnel {
|
|
203
397
|
/** The URL that this tunnel backs. */
|
|
204
398
|
url(): string
|
|
@@ -232,7 +426,11 @@ export class NgrokTcpTunnel {
|
|
|
232
426
|
*/
|
|
233
427
|
close(): Promise<void>
|
|
234
428
|
}
|
|
235
|
-
/**
|
|
429
|
+
/**
|
|
430
|
+
*r" An ngrok tunnel bcking a TLS endpoint.
|
|
431
|
+
*r"
|
|
432
|
+
*r" @group Tunnels
|
|
433
|
+
*/
|
|
236
434
|
export class NgrokTlsTunnel {
|
|
237
435
|
/** The URL that this tunnel backs. */
|
|
238
436
|
url(): string
|
|
@@ -266,7 +464,11 @@ export class NgrokTlsTunnel {
|
|
|
266
464
|
*/
|
|
267
465
|
close(): Promise<void>
|
|
268
466
|
}
|
|
269
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
*r" A labeled ngrok tunnel.
|
|
469
|
+
*r"
|
|
470
|
+
*r" @group Tunnels
|
|
471
|
+
*/
|
|
270
472
|
export class NgrokLabeledTunnel {
|
|
271
473
|
/** The labels this tunnel was started with. */
|
|
272
474
|
labels(): Record<string, string>
|
|
@@ -298,7 +500,11 @@ export class NgrokLabeledTunnel {
|
|
|
298
500
|
*/
|
|
299
501
|
close(): Promise<void>
|
|
300
502
|
}
|
|
301
|
-
/**
|
|
503
|
+
/**
|
|
504
|
+
*r" An ngrok tunnel backing an HTTP endpoint.
|
|
505
|
+
*r"
|
|
506
|
+
*r" @group Tunnel Builders
|
|
507
|
+
*/
|
|
302
508
|
export class NgrokHttpTunnelBuilder {
|
|
303
509
|
/**
|
|
304
510
|
* The scheme that this edge should use.
|
|
@@ -318,13 +524,13 @@ export class NgrokHttpTunnelBuilder {
|
|
|
318
524
|
* Disabled when 0.
|
|
319
525
|
*/
|
|
320
526
|
circuitBreaker(circuitBreaker: number): this
|
|
321
|
-
/**
|
|
527
|
+
/** request_header adds a header to all requests to this edge. */
|
|
322
528
|
requestHeader(name: string, value: string): this
|
|
323
|
-
/**
|
|
529
|
+
/** response_header adds a header to all responses coming from this edge. */
|
|
324
530
|
responseHeader(name: string, value: string): this
|
|
325
|
-
/**
|
|
531
|
+
/** remove_request_header removes a header from requests to this edge. */
|
|
326
532
|
removeRequestHeader(name: string): this
|
|
327
|
-
/**
|
|
533
|
+
/** remove_response_header removes a header from responses from this edge. */
|
|
328
534
|
removeResponseHeader(name: string): this
|
|
329
535
|
/**
|
|
330
536
|
* Credentials for basic authentication.
|
|
@@ -334,6 +540,7 @@ export class NgrokHttpTunnelBuilder {
|
|
|
334
540
|
/**
|
|
335
541
|
* OAuth configuration.
|
|
336
542
|
* If not called, OAuth is disabled.
|
|
543
|
+
* https://ngrok.com/docs/cloud-edge/modules/oauth/
|
|
337
544
|
*/
|
|
338
545
|
oauth(provider: string, allowEmails?: Array<string> | undefined | null, allowDomains?: Array<string> | undefined | null, scopes?: Array<string> | undefined | null): this
|
|
339
546
|
/**
|
|
@@ -368,7 +575,11 @@ export class NgrokHttpTunnelBuilder {
|
|
|
368
575
|
*/
|
|
369
576
|
forwardsTo(forwardsTo: string): this
|
|
370
577
|
}
|
|
371
|
-
/**
|
|
578
|
+
/**
|
|
579
|
+
*r" An ngrok tunnel backing a TCP endpoint.
|
|
580
|
+
*r"
|
|
581
|
+
*r" @group Tunnel Builders
|
|
582
|
+
*/
|
|
372
583
|
export class NgrokTcpTunnelBuilder {
|
|
373
584
|
/** The TCP address to request for this edge. */
|
|
374
585
|
remoteAddr(remoteAddr: string): this
|
|
@@ -394,13 +605,17 @@ export class NgrokTcpTunnelBuilder {
|
|
|
394
605
|
*/
|
|
395
606
|
forwardsTo(forwardsTo: string): this
|
|
396
607
|
}
|
|
397
|
-
/**
|
|
608
|
+
/**
|
|
609
|
+
*r" An ngrok tunnel backing a TLS endpoint.
|
|
610
|
+
*r"
|
|
611
|
+
*r" @group Tunnel Builders
|
|
612
|
+
*/
|
|
398
613
|
export class NgrokTlsTunnelBuilder {
|
|
399
614
|
/** The domain to request for this edge. */
|
|
400
615
|
domain(domain: string): this
|
|
401
616
|
/** Certificates to use for client authentication at the ngrok edge. */
|
|
402
617
|
mutualTlsca(mutualTlsca: Uint8Array): this
|
|
403
|
-
/** The key to use for TLS termination at the ngrok edge in PEM format. */
|
|
618
|
+
/** The certificate and key to use for TLS termination at the ngrok edge in PEM format. */
|
|
404
619
|
termination(certPem: Uint8Array, keyPem: Uint8Array): this
|
|
405
620
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
406
621
|
metadata(metadata: string): this
|
|
@@ -424,7 +639,11 @@ export class NgrokTlsTunnelBuilder {
|
|
|
424
639
|
*/
|
|
425
640
|
forwardsTo(forwardsTo: string): this
|
|
426
641
|
}
|
|
427
|
-
/**
|
|
642
|
+
/**
|
|
643
|
+
*r" A labeled ngrok tunnel.
|
|
644
|
+
*r"
|
|
645
|
+
*r" @group Tunnel Builders
|
|
646
|
+
*/
|
|
428
647
|
export class NgrokLabeledTunnelBuilder {
|
|
429
648
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
430
649
|
metadata(metadata: string): this
|
|
@@ -434,11 +653,16 @@ export class NgrokLabeledTunnelBuilder {
|
|
|
434
653
|
label(label: string, value: string): this
|
|
435
654
|
}
|
|
436
655
|
/** Generate, or convert a given tunnel, into one that can be passed into net.Server.listen(). */
|
|
437
|
-
export function listenable(
|
|
656
|
+
export function listenable(
|
|
657
|
+
tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
|
|
658
|
+
): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
|
|
438
659
|
/** Start the given net.Server listening to a generated, or passed in, tunnel. */
|
|
439
|
-
export function listen(
|
|
440
|
-
|
|
660
|
+
export function listen(
|
|
661
|
+
server: import("net").Server,
|
|
662
|
+
tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
|
|
663
|
+
): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
|
|
664
|
+
/**
|
|
441
665
|
* Register a console.log callback for ngrok INFO logging.
|
|
442
666
|
* Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
|
|
443
667
|
*/
|
|
444
|
-
export function consoleLog(level?: String)
|
|
668
|
+
export function consoleLog(level?: String);
|
package/index.js
CHANGED
|
@@ -252,9 +252,13 @@ if (!nativeBinding) {
|
|
|
252
252
|
throw new Error(`Failed to load native binding`)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
const { loggingCallback, NgrokSessionBuilder, NgrokSession, UpdateRequest, NgrokHttpTunnel, NgrokTcpTunnel, NgrokTlsTunnel, NgrokLabeledTunnel, NgrokHttpTunnelBuilder, NgrokTcpTunnelBuilder, NgrokTlsTunnelBuilder, NgrokLabeledTunnelBuilder } = nativeBinding
|
|
255
|
+
const { connect, disconnect, kill, loggingCallback, authtoken, NgrokSessionBuilder, NgrokSession, UpdateRequest, NgrokHttpTunnel, NgrokTcpTunnel, NgrokTlsTunnel, NgrokLabeledTunnel, NgrokHttpTunnelBuilder, NgrokTcpTunnelBuilder, NgrokTlsTunnelBuilder, NgrokLabeledTunnelBuilder } = nativeBinding
|
|
256
256
|
|
|
257
|
+
module.exports.connect = connect
|
|
258
|
+
module.exports.disconnect = disconnect
|
|
259
|
+
module.exports.kill = kill
|
|
257
260
|
module.exports.loggingCallback = loggingCallback
|
|
261
|
+
module.exports.authtoken = authtoken
|
|
258
262
|
module.exports.NgrokSessionBuilder = NgrokSessionBuilder
|
|
259
263
|
module.exports.NgrokSession = NgrokSession
|
|
260
264
|
module.exports.UpdateRequest = UpdateRequest
|
|
@@ -270,9 +274,9 @@ module.exports.NgrokLabeledTunnelBuilder = NgrokLabeledTunnelBuilder
|
|
|
270
274
|
// javascript trailer
|
|
271
275
|
//
|
|
272
276
|
|
|
273
|
-
const net = require(
|
|
274
|
-
const fs = require(
|
|
275
|
-
const os = require(
|
|
277
|
+
const net = require("net");
|
|
278
|
+
const fs = require("fs");
|
|
279
|
+
const os = require("os");
|
|
276
280
|
|
|
277
281
|
// wrap listen with the bind code for passing to net.Server.listen()
|
|
278
282
|
NgrokHttpTunnelBuilder.prototype._listen = NgrokHttpTunnelBuilder.prototype.listen;
|
|
@@ -286,7 +290,7 @@ NgrokTlsTunnelBuilder.prototype.listen = ngrokBind;
|
|
|
286
290
|
NgrokLabeledTunnelBuilder.prototype.listen = ngrokBind;
|
|
287
291
|
|
|
288
292
|
// Begin listening for new connections on this tunnel,
|
|
289
|
-
// and bind to a local socket so this tunnel can be
|
|
293
|
+
// and bind to a local socket so this tunnel can be
|
|
290
294
|
// passed into net.Server.listen().
|
|
291
295
|
async function ngrokBind(bind) {
|
|
292
296
|
const tunnel = await this._listen();
|
|
@@ -303,30 +307,31 @@ async function ngrokBind(bind) {
|
|
|
303
307
|
function defineTunnelHandle(tunnel, socket) {
|
|
304
308
|
// NodeJS net.Server asks passed-in object for 'handle',
|
|
305
309
|
// Return the native TCP object so the pre-existing socket is used.
|
|
306
|
-
Object.defineProperty(
|
|
307
|
-
get: function() {
|
|
310
|
+
Object.defineProperty(tunnel, "handle", {
|
|
311
|
+
get: function () {
|
|
308
312
|
// turn on forwarding now that it has been requested
|
|
309
|
-
tunnel.forwardTcp(
|
|
313
|
+
tunnel.forwardTcp("localhost:" + socket.address().port);
|
|
310
314
|
return socket._handle;
|
|
311
|
-
}
|
|
315
|
+
},
|
|
312
316
|
});
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
// generate a net.Server listening to a random port
|
|
316
320
|
async function randomTcpSocket() {
|
|
317
|
-
return await asyncListen(new net.Server(), {host:
|
|
321
|
+
return await asyncListen(new net.Server(), { host: "localhost", port: 0 });
|
|
318
322
|
}
|
|
319
323
|
|
|
320
324
|
// NodeJS has not promisified 'net': https://github.com/nodejs/node/issues/21482
|
|
321
325
|
function asyncListen(server, options) {
|
|
322
326
|
return new Promise((resolve, reject) => {
|
|
323
327
|
const socket = server.listen(options);
|
|
324
|
-
socket
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
socket
|
|
329
|
+
.once("listening", () => {
|
|
330
|
+
resolve(socket);
|
|
331
|
+
})
|
|
332
|
+
.once("error", (err) => {
|
|
333
|
+
reject(err);
|
|
334
|
+
});
|
|
330
335
|
});
|
|
331
336
|
}
|
|
332
337
|
|
|
@@ -378,16 +383,16 @@ async function ngrokListen(server, tunnel) {
|
|
|
378
383
|
|
|
379
384
|
async function ngrokLinkTcp(tunnel, server) {
|
|
380
385
|
// random local port
|
|
381
|
-
const socket = await asyncListen(server, {host:
|
|
386
|
+
const socket = await asyncListen(server, { host: "localhost", port: 0 });
|
|
382
387
|
// forward to socket
|
|
383
|
-
tunnel.forwardTcp(
|
|
388
|
+
tunnel.forwardTcp("localhost:" + socket.address().port);
|
|
384
389
|
return socket;
|
|
385
390
|
}
|
|
386
391
|
|
|
387
392
|
async function ngrokLinkPipe(tunnel, server) {
|
|
388
393
|
var proposed = "tun-" + tunnel.id() + ".sock";
|
|
389
|
-
if (platform ==
|
|
390
|
-
proposed =
|
|
394
|
+
if (platform == "win32") {
|
|
395
|
+
proposed = "\\\\.\\pipe\\" + proposed;
|
|
391
396
|
}
|
|
392
397
|
var filename;
|
|
393
398
|
try {
|
|
@@ -405,10 +410,10 @@ async function ngrokLinkPipe(tunnel, server) {
|
|
|
405
410
|
}
|
|
406
411
|
|
|
407
412
|
// begin listening
|
|
408
|
-
const socket = await asyncListen(server, {path: filename});
|
|
413
|
+
const socket = await asyncListen(server, { path: filename });
|
|
409
414
|
// tighten permissions
|
|
410
415
|
try {
|
|
411
|
-
if (platform !=
|
|
416
|
+
if (platform != "win32") {
|
|
412
417
|
fs.chmodSync(filename, fs.constants.S_IRWXU);
|
|
413
418
|
}
|
|
414
419
|
} catch (err) {
|
|
@@ -422,21 +427,21 @@ async function ngrokLinkPipe(tunnel, server) {
|
|
|
422
427
|
}
|
|
423
428
|
|
|
424
429
|
function registerCleanup(tunnel, socket) {
|
|
425
|
-
process.on(
|
|
426
|
-
if (process.listenerCount(
|
|
430
|
+
process.on("SIGINT", function () {
|
|
431
|
+
if (process.listenerCount("SIGINT") > 1) {
|
|
427
432
|
// user has registered a handler, abort this one
|
|
428
433
|
return;
|
|
429
434
|
}
|
|
430
435
|
// close tunnel
|
|
431
436
|
if (tunnel) {
|
|
432
|
-
tunnel.close().then(()=>{
|
|
433
|
-
console.debug(
|
|
437
|
+
tunnel.close().then(() => {
|
|
438
|
+
console.debug("ngrok closed tunnel: " + tunnel.id());
|
|
434
439
|
});
|
|
435
440
|
}
|
|
436
441
|
// close webserver's socket
|
|
437
442
|
if (socket) {
|
|
438
443
|
socket.close(function () {
|
|
439
|
-
console.debug(
|
|
444
|
+
console.debug("ngrok closed socket");
|
|
440
445
|
});
|
|
441
446
|
}
|
|
442
447
|
// unregister any logging callback
|
|
@@ -450,6 +455,117 @@ function consoleLog(level) {
|
|
|
450
455
|
}, level);
|
|
451
456
|
}
|
|
452
457
|
|
|
453
|
-
|
|
454
|
-
|
|
458
|
+
// wrap connect with code to vectorize and split out functions
|
|
459
|
+
const _connect = connect;
|
|
460
|
+
async function ngrokConnect(config) {
|
|
461
|
+
if (Number.isInteger(config) || typeof config === "string" || config instanceof String) {
|
|
462
|
+
address = String(config);
|
|
463
|
+
if (!address.includes(":")) {
|
|
464
|
+
address = `localhost:${address}`;
|
|
465
|
+
}
|
|
466
|
+
config = { addr: address };
|
|
467
|
+
}
|
|
468
|
+
// Convert addr to string to allow for numeric port numbers
|
|
469
|
+
const addr = config["addr"];
|
|
470
|
+
if (Number.isInteger(addr)) config["addr"] = "localhost:" + String(config["addr"]);
|
|
471
|
+
// convert scalar values to arrays to meet what napi-rs expects
|
|
472
|
+
[
|
|
473
|
+
"auth",
|
|
474
|
+
"basic_auth",
|
|
475
|
+
"ip_restriction.allow_cidrs",
|
|
476
|
+
"ip_restriction.deny_cidrs",
|
|
477
|
+
"labels",
|
|
478
|
+
"oauth.allow_domains",
|
|
479
|
+
"oauth.allow_emails",
|
|
480
|
+
"oauth.scopes",
|
|
481
|
+
"oidc.scopes",
|
|
482
|
+
"oidc.allow_domains",
|
|
483
|
+
"oidc.allow_emails",
|
|
484
|
+
"request_header.add",
|
|
485
|
+
"request_header.remove",
|
|
486
|
+
"response_header.add",
|
|
487
|
+
"response_header.remove",
|
|
488
|
+
"schemes",
|
|
489
|
+
].forEach((key) => {
|
|
490
|
+
vectorize(config, key);
|
|
491
|
+
});
|
|
492
|
+
// convert dotted values to underscores for backwards compatibility
|
|
493
|
+
[
|
|
494
|
+
"ip_restriction.allow_cidrs",
|
|
495
|
+
"ip_restriction.deny_cidrs",
|
|
496
|
+
"oauth.allow_domains",
|
|
497
|
+
"oauth.allow_emails",
|
|
498
|
+
"oauth.scopes",
|
|
499
|
+
"oauth.provider",
|
|
500
|
+
"oidc.client_id",
|
|
501
|
+
"oidc.client_secret",
|
|
502
|
+
"oidc.scopes",
|
|
503
|
+
"oidc.issuer_url",
|
|
504
|
+
"oidc.allow_domains",
|
|
505
|
+
"oidc.allow_emails",
|
|
506
|
+
"request_header.add",
|
|
507
|
+
"request_header.remove",
|
|
508
|
+
"response_header.add",
|
|
509
|
+
"response_header.remove",
|
|
510
|
+
"verify_webhook.provider",
|
|
511
|
+
"verify_webhook.secret",
|
|
512
|
+
].forEach((key) => {
|
|
513
|
+
undot(config, key);
|
|
514
|
+
});
|
|
515
|
+
// break out the logging callback function to meet what napi-rs expects
|
|
516
|
+
var on_log_event;
|
|
517
|
+
if (config["onLogEvent"]) {
|
|
518
|
+
const onLogEvent = config.onLogEvent;
|
|
519
|
+
on_log_event = (level, target, message) => {
|
|
520
|
+
onLogEvent(`${level} ${target} - ${message}`);
|
|
521
|
+
};
|
|
522
|
+
config["onLogEvent"] = true;
|
|
523
|
+
}
|
|
524
|
+
// break out the status change callback functions to what napi-rs expects
|
|
525
|
+
var on_connection, on_disconnection;
|
|
526
|
+
if (config["onStatusChange"]) {
|
|
527
|
+
const onStatusChange = config.onStatusChange;
|
|
528
|
+
on_connection = (status, err) => {
|
|
529
|
+
onStatusChange(status);
|
|
530
|
+
};
|
|
531
|
+
on_disconnection = (addr, err) => {
|
|
532
|
+
onStatusChange("closed");
|
|
533
|
+
};
|
|
534
|
+
config["onStatusChange"] = true;
|
|
535
|
+
}
|
|
536
|
+
// call into rust
|
|
537
|
+
return await _connect(config, on_log_event, on_connection, on_disconnection);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function undot(config, dotKey) {
|
|
541
|
+
const noDotKey = dotKey.replace(".", "_");
|
|
542
|
+
if (config[dotKey] == null) return; // no dotKey value, done
|
|
543
|
+
if (config[noDotKey] == null) {
|
|
544
|
+
// nothing at destination, just set and be done
|
|
545
|
+
config[noDotKey] = config[dotKey];
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (config[dotKey] instanceof Array && config[noDotKey] instanceof Array) {
|
|
549
|
+
// merge arrays
|
|
550
|
+
for (const obj of config[dotKey]) {
|
|
551
|
+
config[noDotKey].push(obj);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
// destination exists and is not an array, do nothing so noDotKey can take precedence
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function vectorize(config, key) {
|
|
558
|
+
// backwards compatible keys are passed in, check the new style as well
|
|
559
|
+
const noDotKey = key.replace(".", "_");
|
|
560
|
+
if (key != noDotKey) vectorize(config, noDotKey);
|
|
561
|
+
|
|
562
|
+
if (config[key] == null) return; // no value, done
|
|
563
|
+
if (!(config[key] instanceof Array)) {
|
|
564
|
+
config[key] = [config[key]];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
module.exports.connect = ngrokConnect;
|
|
455
569
|
module.exports.consoleLog = consoleLog;
|
|
570
|
+
module.exports.listen = ngrokListen;
|
|
571
|
+
module.exports.listenable = listenable;
|