Skip to content

Commit 6e196f4

Browse files
committed
Rename connect to forward
1 parent 3da87c7 commit 6e196f4

34 files changed

+403
-253
lines changed

Diff for: README.md

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NodeJS SDK for ngrok
1+
# Javascript SDK for ngrok
22

33
[![npm.rs][npm-badge]][npm-url]
44
[![MIT licensed][mit-badge]][mit-url]
@@ -42,16 +42,16 @@ pnpm add @ngrok/ngrok
4242

4343
1. [Install `@ngrok/ngrok`](#installation)
4444
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 [connect method](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-connect-minimal.js) through port `8080` over `localhost`:
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`:
4646

4747
```jsx
48-
// Require ngrok nodejs sdk
48+
// Require ngrok javascript sdk
4949
const ngrok = require("@ngrok/ngrok");
5050
// import ngrok from '@ngrok/ngrok' // if inside a module
5151

5252
(async function() {
5353
// Establish connectivity
54-
const listener = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
54+
const listener = await ngrok.forward({ addr: 8080, authtoken_from_env: true });
5555

5656
// Output ngrok url to console
5757
console.log(`Ingress established at: ${listener.url()}`);
@@ -71,16 +71,16 @@ A quickstart guide and a full API reference are included in the [ngrok-javascrip
7171
7272
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.
7373
74-
You can set it in the `NGROK_AUTHTOKEN` environment variable and pass `authtoken_from_env: true` to the [connect](https://ngrok.github.io/ngrok-javascript/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:
7575
7676
```jsx
77-
await ngrok.connect({ authtoken_from_env: true, ... });
77+
await ngrok.forward({ authtoken_from_env: true, ... });
7878
```
7979
80-
Or pass the authtoken directly to the [connect](https://ngrok.github.io/ngrok-javascript/functions/connect.html) method:
80+
Or pass the authtoken directly to the [forward](https://ngrok.github.io/ngrok-javascript/functions/forward.html) method:
8181
8282
```jsx
83-
await ngrok.connect({ authtoken: token, ... });
83+
await ngrok.forward({ authtoken: token, ... });
8484
```
8585
8686
Or set it for all connections with the [authtoken](https://ngrok.github.io/ngrok-javascript/functions/authtoken.html) method:
@@ -91,42 +91,42 @@ await ngrok.authtoken(token);
9191
9292
### Connection
9393
94-
The [connect](https://ngrok.github.io/ngrok-javascript/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-javascript/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.
9595
96-
With no arguments the [connect](https://ngrok.github.io/ngrok-javascript/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`:
9797
9898
```jsx
9999
const ngrok = require("@ngrok/ngrok");
100100
// import ngrok from '@ngrok/ngrok' // if inside a module
101101
102102
(async function() {
103-
console.log( (await ngrok.connect()).url() );
103+
console.log( (await ngrok.forward()).url() );
104104
})();
105105
```
106106
107107
You can pass the port number to forward on `localhost`:
108108
109109
```jsx
110-
const listener = await ngrok.connect(4242);
110+
const listener = await ngrok.forward(4242);
111111
```
112112
113113
Or you can specify the host and port via a string:
114114
115115
```jsx
116-
const listener = await ngrok.connect("localhost:4242");
116+
const listener = await ngrok.forward("localhost:4242");
117117
```
118118
119-
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:
120120
121121
```jsx
122-
const listener = await ngrok.connect({ addr: 8080, basic_auth: "ngrok:online1line" });
123-
const listener = 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" });
124124
```
125125
126126
The (optional) `proto` parameter is the listener type, which defaults to `http`. To create a TCP listener:
127127
128128
```jsx
129-
const listener = await ngrok.connect({ proto: 'tcp', addr: 25565 });
129+
const listener = await ngrok.forward({ proto: 'tcp', addr: 25565 });
130130
```
131131
132132
See [Full Configuration](#full-configuration) for the list of possible configuration options.
@@ -179,10 +179,10 @@ See here for a [Full Configuration Example](https://github.com/ngrok/ngrok-javas
179179
180180
### TLS Backends
181181
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 connect:
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:
183183
184184
```jsx
185-
await ngrok.connect({ addr: "https://127.0.0.1:3000", authtoken_from_env: true });
185+
await ngrok.forward({ addr: "https://127.0.0.1:3000", authtoken_from_env: true });
186186
```
187187
188188
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`.
@@ -211,10 +211,10 @@ new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
211211
212212
### Full Configuration
213213
214-
This example shows [all the possible configuration items of ngrok.connect](https://github.com/ngrok/ngrok-javascript/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):
215215
216216
```jsx
217-
const listener = await ngrok.connect({
217+
const listener = await ngrok.forward({
218218
// session configuration
219219
addr: `localhost:8080`, // or `8080` or `unix:${UNIX_SOCKET}`
220220
authtoken: "<authtoken>",
@@ -224,7 +224,7 @@ const listener = await ngrok.connect({
224224
},
225225
session_metadata: "Online in One Line",
226226
// listener configuration
227-
metadata: "example listener metadata from nodejs",
227+
metadata: "example listener metadata from javascript",
228228
domain: "<domain>",
229229
proto: "http",
230230
proxy_proto: "", // One of: "", "1", "2"
@@ -292,8 +292,8 @@ npx degit github:ngrok/ngrok-javascript/examples/express express && cd express &
292292
- [Winston (Logging)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-winston.js)
293293
294294
#### Listeners
295-
* [ngrok.connect (minimal)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-connect-minimal.js)
296-
* [ngrok.connect (full)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-connect-full.js)
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)
297297
* [HTTP (ngrok.listener)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-listen.js)
298298
* [HTTP (SessionBuilder minimal)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-minimum.js)
299299
* [HTTP (SessionBuilder full)](https://github.com/ngrok/ngrok-javascript/blob/main/examples/ngrok-http-full.js)

Diff for: __test__/connect.spec.mjs

+27-16
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ async function validateShutdown(t, httpServer, url, axiosConfig) {
4646
return response;
4747
}
4848

49-
test("connect https", async (t) => {
49+
test("forward https", async (t) => {
5050
const httpServer = await makeHttp();
51-
const listener = await ngrok.connect({
51+
const listener = await ngrok.forward({
5252
addr: httpServer.listenTo,
5353
authtoken: process.env["NGROK_AUTHTOKEN"],
5454
});
@@ -70,44 +70,55 @@ test("connect number", async (t) => {
7070
await validateShutdown(t, httpServer, url);
7171
});
7272

73-
test("connect port string", async (t) => {
73+
test("forward number", async (t) => {
74+
const httpServer = await makeHttp();
75+
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
76+
const listener = await ngrok.forward(parseInt(httpServer.listenTo.split(":")[1], 10));
77+
const url = listener.url();
78+
79+
t.truthy(url);
80+
t.truthy(url.startsWith("https://"), url);
81+
await validateShutdown(t, httpServer, url);
82+
});
83+
84+
test("forward port string", async (t) => {
7485
ngrok.consoleLog();
7586
const httpServer = await makeHttp();
7687
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
77-
const listener = await ngrok.connect(httpServer.listenTo.split(":")[1]);
88+
const listener = await ngrok.forward(httpServer.listenTo.split(":")[1]);
7889
const url = listener.url();
7990

8091
t.truthy(url);
8192
t.truthy(url.startsWith("https://"), url);
8293
await validateShutdown(t, httpServer, url);
8394
});
8495

85-
test("connect addr port string", async (t) => {
96+
test("forward addr port string", async (t) => {
8697
ngrok.consoleLog();
8798
const httpServer = await makeHttp();
8899
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
89-
const listener = await ngrok.connect({ addr: httpServer.listenTo.split(":")[1] });
100+
const listener = await ngrok.forward({ addr: httpServer.listenTo.split(":")[1] });
90101
const url = listener.url();
91102

92103
t.truthy(url);
93104
t.truthy(url.startsWith("https://"), url);
94105
await validateShutdown(t, httpServer, url);
95106
});
96107

97-
test("connect string", async (t) => {
108+
test("forward string", async (t) => {
98109
const httpServer = await makeHttp();
99110
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
100-
const listener = await ngrok.connect(httpServer.listenTo);
111+
const listener = await ngrok.forward(httpServer.listenTo);
101112
const url = listener.url();
102113

103114
t.truthy(url);
104115
t.truthy(url.startsWith("https://"), url);
105116
await validateShutdown(t, httpServer, url);
106117
});
107118

108-
test("connect vectorize", async (t) => {
119+
test("forward vectorize", async (t) => {
109120
const httpServer = await makeHttp();
110-
const listener = await ngrok.connect({
121+
const listener = await ngrok.forward({
111122
// numeric port
112123
addr: parseInt(httpServer.listenTo.split(":")[1], 10),
113124
authtoken: process.env["NGROK_AUTHTOKEN"],
@@ -145,9 +156,9 @@ test("connect vectorize", async (t) => {
145156
t.is("true2", response.headers["x-res-yup2"]);
146157
});
147158

148-
test("connect tcp listener", async (t) => {
159+
test("forward tcp listener", async (t) => {
149160
const httpServer = await makeHttp();
150-
const listener = await ngrok.connect({
161+
const listener = await ngrok.forward({
151162
addr: httpServer.listenTo,
152163
authtoken_from_env: true,
153164
proto: "tcp",
@@ -160,9 +171,9 @@ test("connect tcp listener", async (t) => {
160171
await validateShutdown(t, httpServer, listener.url().replace("tcp:", "http:"));
161172
});
162173

163-
test("connect tls listener", async (t) => {
174+
test("forward tls listener", async (t) => {
164175
const httpServer = await makeHttp();
165-
const listener = await ngrok.connect({
176+
const listener = await ngrok.forward({
166177
addr: httpServer.listenTo,
167178
authtoken_from_env: true,
168179
proto: "tls",
@@ -186,12 +197,12 @@ test("connect tls listener", async (t) => {
186197
});
187198

188199
// serial to not run into double error on a session issue
189-
test.serial("connect bad domain", async (t) => {
200+
test.serial("forward bad domain", async (t) => {
190201
const httpServer = await makeHttp();
191202
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);
192203
const error = await t.throwsAsync(
193204
async () => {
194-
await ngrok.connect({ addr: httpServer.listenTo, domain: "1.21 gigawatts" });
205+
await ngrok.forward({ addr: httpServer.listenTo, domain: "1.21 gigawatts" });
195206
},
196207
{ instanceOf: Error }
197208
);

Diff for: docs/assets/search.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)