@ngrok/ngrok 0.9.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.
- package/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +4 -4
- package/README.md +174 -142
- package/index.d.ts +70 -15
- package/index.js +8 -6
- package/package.json +37 -16
- package/.envrc +0 -1
- package/.gitattributes +0 -3
- package/.prettierrc.json +0 -3
- package/.yarnrc.yml +0 -3
- package/Cargo.toml +0 -34
- package/RELEASE.md +0 -26
- package/build.rs +0 -5
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/HttpListenerBuilder.html +0 -594
- package/docs/classes/LabeledListenerBuilder.html +0 -206
- package/docs/classes/Listener.html +0 -241
- package/docs/classes/Session.html +0 -207
- package/docs/classes/SessionBuilder.html +0 -465
- package/docs/classes/TcpListenerBuilder.html +0 -281
- package/docs/classes/TlsListenerBuilder.html +0 -322
- package/docs/classes/UpdateRequest.html +0 -131
- package/docs/functions/authtoken.html +0 -89
- package/docs/functions/connect.html +0 -89
- package/docs/functions/consoleLog.html +0 -90
- package/docs/functions/disconnect.html +0 -89
- package/docs/functions/getListener.html +0 -89
- package/docs/functions/getListenerByUrl.html +0 -89
- package/docs/functions/kill.html +0 -84
- package/docs/functions/listen.html +0 -92
- package/docs/functions/listenable.html +0 -85
- package/docs/functions/listeners.html +0 -84
- package/docs/functions/loggingCallback.html +0 -108
- package/docs/index.html +0 -292
- package/docs/interfaces/Config.html +0 -734
- package/docs/modules.html +0 -106
- package/examples/domain.crt +0 -18
- package/examples/domain.key +0 -27
- package/examples/express/ngrok-express-quickstart.js +0 -11
- package/examples/express/ngrok-express.js +0 -28
- package/examples/express/package.json +0 -7
- package/examples/fastify/ngrok-fastify.js +0 -26
- package/examples/fastify/package.json +0 -7
- package/examples/hapi/ngrok-hapi.js +0 -35
- package/examples/hapi/package.json +0 -7
- package/examples/koa/ngrok-koa.js +0 -12
- package/examples/koa/package.json +0 -7
- package/examples/nestjs/.eslintrc.js +0 -25
- package/examples/nestjs/.prettierrc +0 -4
- package/examples/nestjs/README.md +0 -73
- package/examples/nestjs/nest-cli.json +0 -8
- package/examples/nestjs/package.json +0 -70
- package/examples/nestjs/src/app.controller.spec.ts +0 -22
- package/examples/nestjs/src/app.controller.ts +0 -12
- package/examples/nestjs/src/app.module.ts +0 -10
- package/examples/nestjs/src/app.service.ts +0 -8
- package/examples/nestjs/src/main.ts +0 -17
- package/examples/nestjs/test/app.e2e-spec.ts +0 -24
- package/examples/nestjs/test/jest-e2e.json +0 -9
- package/examples/nestjs/tsconfig.build.json +0 -4
- package/examples/nestjs/tsconfig.json +0 -21
- package/examples/nextjs/README.md +0 -3
- package/examples/nextjs/next.config.js +0 -12
- package/examples/nextjs/ngrok.config.js +0 -23
- package/examples/nextjs/package.json +0 -6
- package/examples/nextjs/pages/index.js +0 -5
- package/examples/ngrok-connect-full.js +0 -67
- package/examples/ngrok-connect-minimal.js +0 -17
- package/examples/ngrok-http-full.js +0 -81
- package/examples/ngrok-http-minimum.js +0 -18
- package/examples/ngrok-labeled.js +0 -43
- package/examples/ngrok-listen.js +0 -11
- package/examples/ngrok-tcp.js +0 -37
- package/examples/ngrok-tls.js +0 -40
- package/examples/ngrok-typescript.ts +0 -69
- package/examples/ngrok-windows-pipe.js +0 -25
- package/examples/ngrok-winston.js +0 -24
- package/examples/package.json +0 -15
- package/examples/remix/.eslintrc.js +0 -4
- package/examples/remix/README.md +0 -53
- package/examples/remix/app/entry.client.tsx +0 -18
- package/examples/remix/app/entry.server.tsx +0 -101
- package/examples/remix/app/root.tsx +0 -20
- package/examples/remix/app/routes/_index.tsx +0 -30
- package/examples/remix/ngrok.config.js +0 -16
- package/examples/remix/package.json +0 -30
- package/examples/remix/public/favicon.ico +0 -0
- package/examples/remix/remix.config.js +0 -16
- package/examples/remix/remix.env.d.ts +0 -2
- package/examples/remix/tsconfig.json +0 -22
- package/examples/svelte/README.md +0 -38
- package/examples/svelte/jsconfig.json +0 -17
- package/examples/svelte/ngrok.config.cjs +0 -20
- package/examples/svelte/package.json +0 -22
- package/examples/svelte/src/app.d.ts +0 -12
- package/examples/svelte/src/app.html +0 -12
- package/examples/svelte/src/routes/+page.svelte +0 -2
- package/examples/svelte/static/favicon.png +0 -0
- package/examples/svelte/svelte.config.js +0 -14
- package/examples/svelte/vite.config.js +0 -6
- package/examples/vue/.vscode/extensions.json +0 -3
- package/examples/vue/README.md +0 -40
- package/examples/vue/env.d.ts +0 -1
- package/examples/vue/index.html +0 -13
- package/examples/vue/ngrok.config.ts +0 -18
- package/examples/vue/package.json +0 -25
- package/examples/vue/public/favicon.ico +0 -0
- package/examples/vue/src/App.vue +0 -47
- package/examples/vue/src/assets/base.css +0 -74
- package/examples/vue/src/assets/logo.svg +0 -1
- package/examples/vue/src/assets/main.css +0 -35
- package/examples/vue/src/components/HelloWorld.vue +0 -40
- package/examples/vue/src/components/TheWelcome.vue +0 -86
- package/examples/vue/src/components/WelcomeItem.vue +0 -86
- package/examples/vue/src/components/icons/IconCommunity.vue +0 -7
- package/examples/vue/src/components/icons/IconDocumentation.vue +0 -7
- package/examples/vue/src/components/icons/IconEcosystem.vue +0 -7
- package/examples/vue/src/components/icons/IconSupport.vue +0 -7
- package/examples/vue/src/components/icons/IconTooling.vue +0 -19
- package/examples/vue/src/main.ts +0 -6
- package/examples/vue/tsconfig.json +0 -16
- package/examples/vue/tsconfig.node.json +0 -8
- package/examples/vue/vite.config.ts +0 -15
- package/flake.lock +0 -82
- package/flake.nix +0 -111
- package/post-build.js +0 -45
- package/scripts/gc-node-drop.js +0 -49
- package/scripts/gc-rust-drop.js +0 -53
- package/src/config.rs +0 -285
- package/src/connect.rs +0 -342
- package/src/http.rs +0 -244
- package/src/lib.rs +0 -39
- package/src/listener.rs +0 -495
- package/src/listener_builder.rs +0 -204
- package/src/logging.rs +0 -140
- package/src/session.rs +0 -551
- package/src/tcp.rs +0 -18
- package/src/tls.rs +0 -44
- package/trailer.d.ts +0 -15
- package/trailer.js +0 -382
- package/tsconfig.json +0 -8
- package/typedoc.json +0 -3
package/CHANGELOG.md
CHANGED
package/CONTRIBUTING.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Contributing to ngrok-
|
|
1
|
+
# Contributing to ngrok-javascript
|
|
2
2
|
|
|
3
|
-
Thank you for deciding to contribute to ngrok-
|
|
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-
|
|
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-
|
|
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
|
-
#
|
|
1
|
+
# Javascript SDK for ngrok
|
|
2
2
|
|
|
3
3
|
[![npm.rs][npm-badge]][npm-url]
|
|
4
4
|
[![MIT licensed][mit-badge]][mit-url]
|
|
@@ -11,119 +11,136 @@
|
|
|
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-
|
|
15
|
-
[ci-url]: https://github.com/ngrok/ngrok-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
24
|
-
applications. This allows you to quickly build ngrok into your application with no separate process
|
|
25
|
-
to manage.
|
|
21
|
+
# Installation
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
Using npm:
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
```shell
|
|
26
|
+
npm install @ngrok/ngrok
|
|
27
|
+
```
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
Using yarn:
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
yarn add @ngrok/ngrok
|
|
33
|
+
```
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
[npm](https://www.npmjs.com/package/@ngrok/ngrok):
|
|
35
|
+
Using pnpm:
|
|
35
36
|
|
|
36
37
|
```shell
|
|
37
|
-
|
|
38
|
+
pnpm add @ngrok/ngrok
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
[authtoken page of your ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken)
|
|
41
|
+
# Quickstart
|
|
42
42
|
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
const ngrok = require("@ngrok/ngrok");
|
|
47
|
-
(async function() {
|
|
48
|
-
const listener = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
|
|
49
|
-
console.log(`Ingress established at: ${listener.url()}`);
|
|
50
|
-
})();
|
|
51
|
-
```
|
|
66
|
+
# Documentation
|
|
52
67
|
|
|
53
|
-
|
|
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
|
-
|
|
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 [
|
|
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.
|
|
77
|
+
await ngrok.forward({ authtoken_from_env: true, ... });
|
|
63
78
|
```
|
|
64
79
|
|
|
65
|
-
Or pass the authtoken directly to the [
|
|
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.
|
|
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-
|
|
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
|
-
|
|
92
|
+
### Connection
|
|
78
93
|
|
|
79
|
-
The [
|
|
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 [
|
|
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.
|
|
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 listener = await ngrok.
|
|
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 listener = await ngrok.
|
|
116
|
+
const listener = await ngrok.forward("localhost:4242");
|
|
100
117
|
```
|
|
101
118
|
|
|
102
|
-
More options can be passed to the `
|
|
119
|
+
More options can be passed to the `forward` method to customize the connection:
|
|
103
120
|
|
|
104
121
|
```jsx
|
|
105
|
-
const listener = await ngrok.
|
|
106
|
-
const listener = await ngrok.
|
|
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 listener = await ngrok.
|
|
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
|
-
|
|
134
|
+
### Disconnection
|
|
118
135
|
|
|
119
|
-
The [close](https://ngrok.github.io/ngrok-
|
|
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
139
|
const listener = await ngrok.getListenerByUrl(url);
|
|
123
140
|
await listener.close();
|
|
124
141
|
```
|
|
125
142
|
|
|
126
|
-
Or use the [disconnect](https://ngrok.github.io/ngrok-
|
|
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):
|
|
127
144
|
|
|
128
145
|
```jsx
|
|
129
146
|
await ngrok.disconnect(listener.url());
|
|
@@ -135,20 +152,69 @@ Or omit the `url()` to close all listeners:
|
|
|
135
152
|
await ngrok.disconnect();
|
|
136
153
|
```
|
|
137
154
|
|
|
138
|
-
|
|
155
|
+
### Listing Listeners
|
|
139
156
|
|
|
140
|
-
To list all current non-closed listeners use the [listeners](https://ngrok.github.io/ngrok-
|
|
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
|
-
|
|
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.
|
|
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 listener = await ngrok.
|
|
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 listener = await ngrok.connect({
|
|
|
158
224
|
},
|
|
159
225
|
session_metadata: "Online in One Line",
|
|
160
226
|
// listener configuration
|
|
161
|
-
|
|
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
|
-
|
|
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 listener = 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-
|
|
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-
|
|
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-
|
|
208
|
-
```
|
|
209
|
-
|
|
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 });
|
|
277
|
+
npx degit github:ngrok/ngrok-javascript/examples/express express && cd express && npm i
|
|
255
278
|
```
|
|
256
279
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
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
|
-
|
|
324
|
+
- [NAPI-RS](https://napi.rs/), an excellent system to ease development and building of Rust plugins for NodeJS.
|
|
301
325
|
|
|
302
|
-
#
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
345
|
+
### Contributions
|
|
314
346
|
|
|
315
347
|
Unless you explicitly state otherwise, any contribution intentionally submitted
|
|
316
|
-
for inclusion in ngrok-
|
|
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.
|