@ngrok/ngrok 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/CONTRIBUTING.md +4 -4
  3. package/README.md +179 -147
  4. package/index.d.ts +71 -16
  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 -85
  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 -340
  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
package/CHANGELOG.md CHANGED
@@ -1,7 +1,17 @@
1
+ ## 0.9.1:
2
+
3
+ - Move to `ngrok.forward` from `ngrok.connect`, keeping an alias.
4
+ - Rename to `ngrok-javascript`.
5
+ - Smaller number of files packaged.
6
+
7
+ ## 0.9.0:
8
+
9
+ - `ngrok.connect` now returns the full `Listener` object.
10
+
1
11
  ## 0.8.0:
2
12
 
3
- - Add `allowUserAgent` and `denyUserAgent` options to HTTP listeners
4
- - Add `clientId` and `clientSecret` options to OAuth
13
+ - Add `allowUserAgent` and `denyUserAgent` options to HTTP listeners.
14
+ - Add `clientId` and `clientSecret` options to OAuth.
5
15
 
6
16
  ## 0.7.1:
7
17
 
package/CONTRIBUTING.md CHANGED
@@ -1,13 +1,13 @@
1
- # Contributing to ngrok-nodejs
1
+ # Contributing to ngrok-javascript
2
2
 
3
- Thank you for deciding to contribute to ngrok-nodejs!
3
+ Thank you for deciding to contribute to ngrok-javascript!
4
4
 
5
5
  ## Reporting a bug
6
6
 
7
- To report a bug, please [open a new issue](https://github.com/ngrok/ngrok-nodejs/issues/new) with clear reproduction steps. We will triage and investigate these issues at a regular interval.
7
+ To report a bug, please [open a new issue](https://github.com/ngrok/ngrok-javascript/issues/new) with clear reproduction steps. We will triage and investigate these issues at a regular interval.
8
8
 
9
9
  ## Contributing code
10
10
 
11
11
  Bugfixes and small improvements are always appreciated!
12
12
 
13
- For any larger changes or features, please [open a new issue](https://github.com/ngrok/ngrok-nodejs/issues/new) first to discuss whether the change makes sense. When in doubt, it's always okay to open an issue first.
13
+ For any larger changes or features, please [open a new issue](https://github.com/ngrok/ngrok-javascript/issues/new) first to discuss whether the change makes sense. When in doubt, it's always okay to open an issue first.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # The ngrok Agent SDK for NodeJS
1
+ # Javascript SDK for ngrok
2
2
 
3
3
  [![npm.rs][npm-badge]][npm-url]
4
4
  [![MIT licensed][mit-badge]][mit-url]
@@ -11,144 +11,210 @@
11
11
  [mit-url]: https://github.com/ngrok/ngrok-rust/blob/main/LICENSE-MIT
12
12
  [apache-badge]: https://img.shields.io/badge/license-Apache_2.0-blue.svg
13
13
  [apache-url]: https://github.com/ngrok/ngrok-rust/blob/main/LICENSE-APACHE
14
- [ci-badge]: https://github.com/ngrok/ngrok-nodejs/actions/workflows/ci.yml/badge.svg
15
- [ci-url]: https://github.com/ngrok/ngrok-nodejs/actions/workflows/ci.yml
14
+ [ci-badge]: https://github.com/ngrok/ngrok-javascript/actions/workflows/ci.yml/badge.svg
15
+ [ci-url]: https://github.com/ngrok/ngrok-javascript/actions/workflows/ci.yml
16
16
 
17
- **Note: This is beta-quality software. Interfaces may change without warning.**
17
+ `ngrok-javascript` is the official Node.js SDK for ngrok that requires no binaries. Quickly enable secure production-ready connectivity to your applications and services directly from your code.
18
18
 
19
- [ngrok](https://ngrok.com) is a globally distributed reverse proxy commonly used for quickly getting a public URL to a
20
- service running inside a private network, such as on your local laptop. The ngrok agent is usually
21
- deployed inside a private network and is used to communicate with the ngrok cloud service.
19
+ [ngrok](https://ngrok.com) is a globally distributed gateway that provides secure connectivity for applications and services running in any environment.
22
20
 
23
- This is the ngrok agent in library form, suitable for integrating directly into NodeJS
24
- applications. This allows you to quickly build ngrok into your application with no separate process
25
- to manage.
21
+ # Installation
26
22
 
27
- # Documentation
23
+ Using npm:
24
+
25
+ ```shell
26
+ npm install @ngrok/ngrok
27
+ ```
28
28
 
29
- A quickstart guide and a full API reference are included in the [ngrok-nodejs API documentation](https://ngrok.github.io/ngrok-nodejs/).
29
+ Using yarn:
30
30
 
31
- # Quickstart
31
+ ```shell
32
+ yarn add @ngrok/ngrok
33
+ ```
32
34
 
33
- 1. Install the `ngrok-nodejs` package from
34
- [npm](https://www.npmjs.com/package/@ngrok/ngrok):
35
+ Using pnpm:
35
36
 
36
37
  ```shell
37
- npm install @ngrok/ngrok
38
+ pnpm add @ngrok/ngrok
38
39
  ```
39
40
 
40
- 2. After you've installed the package, you'll need an authtoken. Retrieve one on the
41
- [authtoken page of your ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken)
41
+ # Quickstart
42
42
 
43
- 3. Add the following code block using the [connect method](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-minimal.js) to expose your nodejs application at port `8080` on `localhost`:
43
+ 1. [Install `@ngrok/ngrok`](#installation)
44
+ 2. Export your [authtoken from the ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken) as `NGROK_AUTHTOKEN` in your terminal
45
+ 3. Add the following code to your application to establish connectivity via the [forward method](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-forward-minimal.js) through port `8080` over `localhost`:
46
+
47
+ ```jsx
48
+ // Require ngrok javascript sdk
49
+ const ngrok = require("@ngrok/ngrok");
50
+ // import ngrok from '@ngrok/ngrok' // if inside a module
51
+
52
+ (async function() {
53
+ // Establish connectivity
54
+ const listener = await ngrok.forward({ addr: 8080, authtoken_from_env: true });
55
+
56
+ // Output ngrok url to console
57
+ console.log(`Ingress established at: ${listener.url()}`);
58
+ })();
59
+ ```
60
+
61
+ That's it! Your application should now be available through the url output in your terminal.
62
+
63
+ > **Note**
64
+ > You can find more examples in [the examples directory](https://github.com/ngrok/ngrok-javascript/tree/main/examples).
44
65
 
45
- ```jsx
46
- const ngrok = require("@ngrok/ngrok");
47
- (async function() {
48
- const url = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
49
- console.log(`Ingress established at: ${url}`);
50
- })();
51
- ```
66
+ # Documentation
52
67
 
53
- You can find more examples in [the /examples directory](https://github.com/ngrok/ngrok-nodejs/tree/main/examples).
68
+ A quickstart guide and a full API reference are included in the [ngrok-javascript documentation](https://ngrok.github.io/ngrok-javascript/).
54
69
 
55
- ## Authorization
70
+ ### Authorization
56
71
 
57
72
  To use most of ngrok's features, you'll need an authtoken. To obtain one, sign up for free at [ngrok.com](https://dashboard.ngrok.com/signup) and retrieve it from the [authtoken page of your ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken). Once you have copied your authtoken, you can reference it in several ways.
58
73
 
59
- You can set it in the `NGROK_AUTHTOKEN` environment variable and pass `authtoken_from_env: true` to the [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method:
74
+ You can set it in the `NGROK_AUTHTOKEN` environment variable and pass `authtoken_from_env: true` to the [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method:
60
75
 
61
76
  ```jsx
62
- await ngrok.connect({authtoken_from_env: true, ...});
77
+ await ngrok.forward({ authtoken_from_env: true, ... });
63
78
  ```
64
79
 
65
- Or pass the authtoken directly to the [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method:
80
+ Or pass the authtoken directly to the [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method:
66
81
 
67
82
  ```jsx
68
- await ngrok.connect({authtoken: token, ...});
83
+ await ngrok.forward({ authtoken: token, ... });
69
84
  ```
70
85
 
71
- Or set it for all connections with the [authtoken](https://ngrok.github.io/ngrok-nodejs/functions/authtoken.html) method:
86
+ Or set it for all connections with the [authtoken](https://ngrok.github.io/ngrok-javascript/functions/authtoken.html) method:
72
87
 
73
88
  ```jsx
74
89
  await ngrok.authtoken(token);
75
90
  ```
76
91
 
77
- ## Connection
92
+ ### Connection
78
93
 
79
- The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method is the easiest way to start an ngrok session and establish a listener to a specified address. The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method returns a promise that resolves to the public URL of the listener.
94
+ The [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method is the easiest way to start an ngrok session and establish a listener to a specified address. The [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method returns a promise that resolves to the public URL of the listener.
80
95
 
81
- With no arguments the [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method will start an HTTP listener to `localhost` port `80`:
96
+ With no arguments the [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method will start an HTTP listener to `localhost` port `80`:
82
97
 
83
98
  ```jsx
84
99
  const ngrok = require("@ngrok/ngrok");
100
+ // import ngrok from '@ngrok/ngrok' // if inside a module
101
+
85
102
  (async function() {
86
- console.log( await ngrok.connect() );
103
+ console.log( (await ngrok.forward()).url() );
87
104
  })();
88
105
  ```
89
106
 
90
107
  You can pass the port number to forward on `localhost`:
91
108
 
92
109
  ```jsx
93
- const url = await ngrok.connect(4242);
110
+ const listener = await ngrok.forward(4242);
94
111
  ```
95
112
 
96
113
  Or you can specify the host and port via a string:
97
114
 
98
115
  ```jsx
99
- const url = await ngrok.connect("localhost:4242");
116
+ const listener = await ngrok.forward("localhost:4242");
100
117
  ```
101
118
 
102
- More options can be passed to the `connect` method to customize the connection:
119
+ More options can be passed to the `forward` method to customize the connection:
103
120
 
104
121
  ```jsx
105
- const url = await ngrok.connect({addr: 8080, basic_auth: "ngrok:online1line"});
106
- const url = await ngrok.connect({addr: 8080, oauth_provider: "google", oauth_allow_domains: "example.com"});
122
+ const listener = await ngrok.forward({ addr: 8080, basic_auth: "ngrok:online1line" });
123
+ const listener = await ngrok.forward({ addr: 8080, oauth_provider: "google", oauth_allow_domains: "example.com" });
107
124
  ```
108
125
 
109
126
  The (optional) `proto` parameter is the listener type, which defaults to `http`. To create a TCP listener:
110
127
 
111
128
  ```jsx
112
- const url = await ngrok.connect({proto: 'tcp', addr: 25565});
129
+ const listener = await ngrok.forward({ proto: 'tcp', addr: 25565 });
113
130
  ```
114
131
 
115
132
  See [Full Configuration](#full-configuration) for the list of possible configuration options.
116
133
 
117
- ## Disconnection
134
+ ### Disconnection
118
135
 
119
- To close a listener use the [disconnect](https://ngrok.github.io/ngrok-nodejs/functions/disconnect.html) method with the `url` of the listener to close:
136
+ The [close](https://ngrok.github.io/ngrok-javascript/classes/Listener.html#close) method on a listener will shut it down, and also stop the ngrok session if it is no longer needed. This method returns a promise that resolves when the listener is closed.
120
137
 
121
138
  ```jsx
122
- await ngrok.disconnect(url);
139
+ const listener = await ngrok.getListenerByUrl(url);
140
+ await listener.close();
123
141
  ```
124
142
 
125
- Or omit the `url` to close all listeners:
143
+ Or use the [disconnect](https://ngrok.github.io/ngrok-javascript/functions/disconnect.html) method with the `url()` of the listener to close (or id() for a Labeled Listener):
126
144
 
127
145
  ```jsx
128
- await ngrok.disconnect();
146
+ await ngrok.disconnect(listener.url());
129
147
  ```
130
148
 
131
- The [close](https://ngrok.github.io/ngrok-nodejs/classes/Listener.html#close) method on a listener will shut it down, and also stop the ngrok session if it is no longer needed. This method returns a promise that resolves when the listener is closed.
149
+ Or omit the `url()` to close all listeners:
132
150
 
133
151
  ```jsx
134
- const listener = await ngrok.getListenerByUrl(url);
135
- await listener.close();
152
+ await ngrok.disconnect();
136
153
  ```
137
154
 
138
- ## Listing Listeners
155
+ ### Listing Listeners
139
156
 
140
- To list all current non-closed listeners use the [listeners](https://ngrok.github.io/ngrok-nodejs/functions/listeners.html) method:
157
+ To list all current non-closed listeners use the [listeners](https://ngrok.github.io/ngrok-javascript/functions/listeners.html) method:
141
158
 
142
159
  ```jsx
143
160
  const listeners = await ngrok.listeners();
144
161
  ```
145
162
 
146
- # Full Configuration
163
+ ### Builders
164
+
165
+ For more control over Sessions and Listeners, the builder classes can be used.
166
+
167
+ A minimal example using the builder class looks like [the following](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-minimum.js):
168
+
169
+ ```jsx
170
+ async function create_listener() {
171
+ const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
172
+ const listener = await session.httpEndpoint().listen();
173
+ console.log("Ingress established at:", listener.url());
174
+ listener.forward("localhost:8081");
175
+ }
176
+ ```
177
+
178
+ See here for a [Full Configuration Example](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-full.js)
179
+
180
+ ### TLS Backends
181
+
182
+ As of version `0.7.0` there is backend TLS connection support, validated by a filepath specified in the `SSL_CERT_FILE` environment variable, or falling back to the host OS installed trusted certificate authorities. So it is now possible to do this to forward:
183
+
184
+ ```jsx
185
+ await ngrok.forward({ addr: "https://127.0.0.1:3000", authtoken_from_env: true });
186
+ ```
187
+
188
+ If the service is using certs not trusted by the OS, such as self-signed certificates, add an environment variable like this before running: `SSL_CERT_FILE=/path/to/ca.crt`.
189
+
190
+ ### Async Programming
191
+
192
+ All methods return a `Promise` and are suitable for use in asynchronous
193
+ programming. You can use callback chaining with `.then()` and `.catch()` syntax
194
+ or the `await` keyword to wait for completion of an API call.
195
+
196
+ #### Error Handling
197
+
198
+ All asynchronous functions will throw an error on failure to set up a session or listener,
199
+ which can be caught and dealt with using try/catch or then/catch statements:
200
+
201
+ ```jsx
202
+ new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
203
+ .then((session) => {
204
+ session.httpEndpoint().listen()
205
+ .then((tun) => {})
206
+ .catch(err => console.log('listener setup error: ' + err))
207
+ })
208
+ .catch(err => console.log('session setup error: ' + err))
209
+ .await;
210
+ ```
211
+
212
+ ### Full Configuration
147
213
 
148
- This example shows [all the possible configuration items of ngrok.connect](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-full.js):
214
+ This example shows [all the possible configuration items of ngrok.forward](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-forward-full.js):
149
215
 
150
216
  ```jsx
151
- const url = await ngrok.connect({
217
+ const listener = await ngrok.forward({
152
218
  // session configuration
153
219
  addr: `localhost:8080`, // or `8080` or `unix:${UNIX_SOCKET}`
154
220
  authtoken: "<authtoken>",
@@ -158,15 +224,21 @@ const url = await ngrok.connect({
158
224
  },
159
225
  session_metadata: "Online in One Line",
160
226
  // listener configuration
161
- allow_user_agent: "^mozilla.*",
227
+ metadata: "example listener metadata from javascript",
228
+ domain: "<domain>",
229
+ proto: "http",
230
+ proxy_proto: "", // One of: "", "1", "2"
231
+ schemes: ["HTTPS"],
232
+ // module configuration
162
233
  basic_auth: ["ngrok:online1line"],
163
234
  circuit_breaker: 0.1,
164
235
  compression: true,
236
+ allow_user_agent: "^mozilla.*",
165
237
  deny_user_agent: "^curl.*",
166
- domain: "<domain>",
167
238
  ip_restriction_allow_cidrs: ["0.0.0.0/0"],
168
239
  ip_restriction_deny_cidrs: ["10.1.1.1/32"],
169
- metadata: "example listener metadata from nodejs",
240
+ crt: fs.readFileSync("crt.pem", "utf8"),
241
+ key: fs.readFileSync("key.pem", "utf8"),
170
242
  mutual_tls_cas: [fs.readFileSync('ca.crt', 'utf8')],
171
243
  oauth_provider: "google",
172
244
  oauth_allow_domains: ["<domain>"],
@@ -180,103 +252,55 @@ const url = await ngrok.connect({
180
252
  oidc_allow_domains: ["<domain>"],
181
253
  oidc_allow_emails: ["<email>"],
182
254
  oidc_scopes: ["<scope>"],
183
- proxy_proto: "", // One of: "", "1", "2"
184
255
  request_header_remove: ["X-Req-Nope"],
185
256
  response_header_remove: ["X-Res-Nope"],
186
257
  request_header_add: ["X-Req-Yup:true"],
187
258
  response_header_add: ["X-Res-Yup:true"],
188
- schemes: ["HTTPS"],
189
259
  verify_webhook_provider: "twilio",
190
260
  verify_webhook_secret: "asdf",
191
261
  websocket_tcp_converter: true,
192
262
  });
193
263
  ```
194
264
 
195
- The [Config](https://ngrok.github.io/ngrok-nodejs/interfaces/Config.html) interface also shows all the available options.
265
+ The [Config](https://ngrok.github.io/ngrok-javascript/interfaces/Config.html) interface also shows all the available options.
196
266
 
197
267
  # Examples
198
268
 
199
269
  Degit can be used for cloning and running an example directory like this:
200
270
  ```bash
201
- npx degit github:ngrok/ngrok-nodejs/examples/<example> <folder-name>
271
+ npx degit github:ngrok/ngrok-javascript/examples/<example> <folder-name>
202
272
  cd <folder-name>
203
273
  npm i
204
274
  ```
205
275
  For example:
206
276
  ```bash
207
- npx degit github:ngrok/ngrok-nodejs/examples/express express && cd express && npm i
277
+ npx degit github:ngrok/ngrok-javascript/examples/express express && cd express && npm i
208
278
  ```
209
279
 
210
- ## Frameworks
211
- * [AWS App Runner](https://aws.amazon.com/apprunner/) - See the [ngrok SDK Serverless Example](https://github.com/ngrok/ngrok-sdk-serverless-example) repository
212
- * [Express](https://expressjs.com/) - [Quickstart Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/express/ngrok-express-quickstart.js), [Configuration Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/express/ngrok-express.js)
213
- * [Fastify](https://www.fastify.io/) - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/fastify/ngrok-fastify.js)
214
- * [Hapi](https://hapi.dev/) - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/hapi/ngrok-hapi.js)
215
- * [Koa](https://koajs.com/) - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/koa/ngrok-koa.js)
216
- * [Nest.js](https://nestjs.com/) - [Example main.ts](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/nestjs/src/main.ts)
217
- * [Next.js](https://nextjs.org/) - [Example next.config.js](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/nextjs/next.config.js) loading [ngrok.config.js](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/nextjs/ngrok.config.js)
218
- * [Remix](https://remix.run/) - [Example remix.config.js](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/remix/remix.config.js) loading [ngrok.config.js](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/remix/ngrok.config.js)
219
- * [Svelte](https://svelte.dev/) - [Example svelte.config.js](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/svelte/svelte.config.js) (works in vite.config.js too) loading [ngrok.config.cjs](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/svelte/ngrok.config.cjs)
220
- * [Typescript](https://www.typescriptlang.org/) - [Example ts-node](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-typescript.ts)
221
- * [Vue](https://vuejs.org/) - [Example vite.config.ts](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/vue/vite.config.ts) loading [ngrok.config.ts](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/vue/ngrok.config.ts)
222
- * [Winston](https://github.com/winstonjs/winston#readme) Logging - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-winston.js)
223
-
224
- ## Listener Types
225
- * ngrok.connect - [ngrok.connect Minimal Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-minimal.js), [Full ngrok.connect Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-full.js)
226
- * HTTP - [ngrok.listen Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-listen.js), [Minimal Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-minimum.js), [Full Configuration Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-full.js)
227
- * Labeled - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-labeled.js)
228
- * TCP - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-tcp.js)
229
- * TLS - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-tls.js)
230
- * Windows Pipe - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-windows-pipe.js)
231
-
232
- # Builders
233
-
234
- For more control over Sessions and Listeners, the builder classes can be used.
235
-
236
- A minimal example using the builder class looks like [the following](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-minimum.js):
237
-
238
- ```jsx
239
- async function create_listener() {
240
- const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
241
- const listener = await session.httpEndpoint().listen();
242
- console.log("Ingress established at:", listener.url());
243
- listener.forward("localhost:8081");
244
- }
245
- ```
246
-
247
- See here for a [Full Configuration Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-full.js)
248
-
249
- ## TLS Backends
250
-
251
- As of version `0.7.0` there is backend TLS connection support, validated by a filepath specified in the `SSL_CERT_FILE` environment variable, or falling back to the host OS installed trusted certificate authorities. So it is now possible to do this to connect:
252
-
253
- ```jsx
254
- await ngrok.connect({ addr: "https://127.0.0.1:3000", authtoken_from_env: true });
255
- ```
256
-
257
- If the service is using certs not trusted by the OS, such as self-signed certificates, add an environment variable like this before running: `SSL_CERT_FILE=/path/to/ca.crt`.
258
-
259
- # Async Programming
260
-
261
- All methods return a `Promise` and are suitable for use in asynchronous
262
- programming. You can use callback chaining with `.then()` and `.catch()` syntax
263
- or the `await` keyword to wait for completion of an API call.
264
-
265
- ### Error Handling
266
-
267
- The asynchronous functions will throw an error on failure to set up a session or listener,
268
- which can be caught and dealt with using standard then/catch semantics.
269
-
270
- ```jsx
271
- new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
272
- .then((session) => {
273
- session.httpEndpoint().listen()
274
- .then((tun) => {})
275
- .catch(err => console.log('listener setup error: ' + err))
276
- })
277
- .catch(err => console.log('session setup error: ' + err))
278
- .await;
279
- ```
280
+ #### Frameworks
281
+ - [AWS App Runner](https://github.com/ngrok/ngrok-sdk-serverless-example)
282
+ - [Express](https://github.com/ngrok/ngrok-javascript/blob/main/examples/express)
283
+ - [Fastify Example](https://github.com/ngrok/ngrok-javascript/blob/main/examples/fastify)
284
+ - [Hapi Example](https://github.com/ngrok/ngrok-javascript/blob/main/examples/hapi)
285
+ - [Koa Example](https://github.com/ngrok/ngrok-javascript/blob/main/examples/koa)
286
+ - [Nest.js](https://github.com/ngrok/ngrok-javascript/blob/main/examples/nestjs)
287
+ - [Next.js](https://github.com/ngrok/ngrok-javascript/blob/main/examples/nextjs)
288
+ - [Remix](https://github.com/ngrok/ngrok-javascript/blob/main/examples/remix)
289
+ - [Svelte](https://github.com/ngrok/ngrok-javascript/blob/main/examples/svelte)
290
+ - [Typescript](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-typescript.ts)
291
+ - [Vue](https://github.com/ngrok/ngrok-javascript/blob/main/examples/vue)
292
+ - [Winston (Logging)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-winston.js)
293
+
294
+ #### Listeners
295
+ * [ngrok.forward (minimal)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-forward-minimal.js)
296
+ * [ngrok.forward (full)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-forward-full.js)
297
+ * [HTTP (ngrok.listener)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-listen.js)
298
+ * [HTTP (SessionBuilder minimal)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-minimum.js)
299
+ * [HTTP (SessionBuilder full)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-full.js)
300
+ * [Labeled](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-labeled.js)
301
+ * [TCP](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-tcp.js)
302
+ * [TLS](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-tls.js)
303
+ * [Windows Pipe](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-windows-pipe.js)
280
304
 
281
305
  # Platform Support
282
306
 
@@ -291,27 +315,35 @@ Pre-built binaries are provided on NPM for the following platforms:
291
315
  | FreeBSD | | ✓ | | |
292
316
  | Android | | | ✓ | ✓ |
293
317
 
294
- ngrok-nodejs, and [ngrok-rust](https://github.com/ngrok/ngrok-rust/) which it depends on, are open source, so it may be possible to build them for other platforms.
295
-
296
- * Windows-aarch64 will be supported after the next release of [Ring](https://github.com/briansmith/ring/issues/1167).
318
+ > **Note**
319
+ > `ngrok-javascript`, and [ngrok-rust](https://github.com/ngrok/ngrok-rust/) which it depends on, are open source, so it may be possible to build them for other platforms.
320
+ > * `Windows-aarch64` will be supported after the next release of [Ring](https://github.com/briansmith/ring/issues/1167).
297
321
 
298
322
  # Dependencies
299
323
 
300
- This project relies on [NAPI-RS](https://napi.rs/), an excellent system to ease development and building of Rust plugins for NodeJS.
324
+ - [NAPI-RS](https://napi.rs/), an excellent system to ease development and building of Rust plugins for NodeJS.
301
325
 
302
- # License
326
+ # Changelog
327
+
328
+ Changes to `ngrok-javascript` are tracked under [CHANGELOG.md](https://github.com/ngrok/ngrok-javascript/blob/main/CHANGELOG.md).
303
329
 
304
- This project is licensed under either of
305
330
 
306
- * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
307
- http://www.apache.org/licenses/LICENSE-2.0)
308
- * MIT license ([LICENSE-MIT](LICENSE-MIT) or
309
- http://opensource.org/licenses/MIT)
331
+ # Join the ngrok Community
332
+
333
+ - Check out [our official docs](https://docs.ngrok.com)
334
+ - Read about updates on [our blog](https://blog.ngrok.com)
335
+ - Open an [issue](https://github.com/ngrok/ngrok-javascript/issues) or [pull request](https://github.com/ngrok/ngrok-javascript/pulls)
336
+ - Join our [Slack community](https://ngrok.com/slack)
337
+ - Follow us on [X / Twitter (@ngrokHQ)](https://twitter.com/ngrokhq)
338
+ - Subscribe to our [Youtube channel (@ngrokHQ)](https://www.youtube.com/@ngrokhq)
339
+
340
+ # License
310
341
 
311
- at your option.
342
+ This work is dual-licensed under [Apache, Version 2.0](LICENSE-APACHE) and [MIT](LICENSE-MIT).
343
+ You can choose between one of them if you use this work.
312
344
 
313
- ### Contribution
345
+ ### Contributions
314
346
 
315
347
  Unless you explicitly state otherwise, any contribution intentionally submitted
316
- for inclusion in ngrok-nodejs by you, as defined in the Apache-2.0 license, shall be
348
+ for inclusion in `ngrok-javascript` by you, as defined in the Apache-2.0 license, shall be
317
349
  dual licensed as above, without any additional terms or conditions.