@ngrok/ngrok 0.0.11 → 0.0.12
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 +13 -0
- package/Cargo.toml +2 -2
- package/examples/ngrok-express-quickstart.js +11 -0
- package/examples/ngrok-express.js +18 -3
- package/index.d.ts +2 -0
- package/index.js +8 -1
- package/package.json +15 -15
- package/src/session.rs +10 -0
- package/trailer.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 0.0.12:
|
|
2
|
+
|
|
3
|
+
* Added NgrokSession.close().
|
|
4
|
+
* Cleanly shutdown when listen is called with a pre-configured tunnel.
|
|
5
|
+
|
|
6
|
+
## 0.0.11:
|
|
7
|
+
|
|
8
|
+
* Cleanly shutdown on all platforms when there are callbacks registered.
|
|
9
|
+
|
|
10
|
+
## 0.0.10:
|
|
11
|
+
|
|
12
|
+
* Child client versioning support.
|
|
13
|
+
|
|
1
14
|
## 0.0.9:
|
|
2
15
|
|
|
3
16
|
* Support for named pipes on Windows.
|
package/Cargo.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
edition = "2021"
|
|
3
3
|
name = "ngrok-js"
|
|
4
|
-
version = "0.0.
|
|
4
|
+
version = "0.0.12"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib"]
|
|
@@ -13,7 +13,7 @@ lazy_static = "1.4.0"
|
|
|
13
13
|
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
14
14
|
napi = { version = "2.12.0", default-features = false, features = ["napi4", "tokio_rt"] }
|
|
15
15
|
napi-derive = "2.12.1"
|
|
16
|
-
ngrok = { version = "
|
|
16
|
+
ngrok = { version = "0.11.0" }
|
|
17
17
|
parking_lot = "0.12.1"
|
|
18
18
|
tokio = { version = "1.23.0", features = ["sync"] }
|
|
19
19
|
tracing = "0.1.37"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const express = require('express')
|
|
2
|
+
const ngrok = require('@ngrok/ngrok')
|
|
3
|
+
const app = express()
|
|
4
|
+
|
|
5
|
+
app.get('/', (req, res) => {
|
|
6
|
+
res.send('Hello World!')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
ngrok.listen(app).then(() => {
|
|
10
|
+
console.log("established tunnel at: " + app.tunnel.url());
|
|
11
|
+
});
|
|
@@ -6,6 +6,21 @@ app.get('/', (req, res) => {
|
|
|
6
6
|
res.send('Hello World!')
|
|
7
7
|
})
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
async function setup() {
|
|
10
|
+
// create session
|
|
11
|
+
const session = await new ngrok.NgrokSessionBuilder()
|
|
12
|
+
.authtokenFromEnv()
|
|
13
|
+
.metadata("Online in One Line")
|
|
14
|
+
.connect();
|
|
15
|
+
// create tunnel
|
|
16
|
+
const tunnel = await session.httpEndpoint()
|
|
17
|
+
.allowCidr("0.0.0.0/0")
|
|
18
|
+
.oauth("google")
|
|
19
|
+
.requestHeader("X-Req-Yup", "true")
|
|
20
|
+
.listen();
|
|
21
|
+
console.log("tunnel established at: " + tunnel.url());
|
|
22
|
+
// link tunnel to app
|
|
23
|
+
ngrok.listen(app, tunnel)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setup();
|
package/index.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ export class NgrokSession {
|
|
|
126
126
|
labeledTunnel(): NgrokLabeledTunnelBuilder
|
|
127
127
|
/** Close a tunnel with the given ID. */
|
|
128
128
|
closeTunnel(id: string): Promise<void>
|
|
129
|
+
/** Close the ngrok session. */
|
|
130
|
+
close(): Promise<void>
|
|
129
131
|
}
|
|
130
132
|
export class UpdateRequest {
|
|
131
133
|
/** The version that the agent is requested to update to. */
|
package/index.js
CHANGED
|
@@ -292,6 +292,7 @@ async function ngrokBind(bind) {
|
|
|
292
292
|
const tunnel = await this._listen();
|
|
293
293
|
if (bind !== false) {
|
|
294
294
|
const socket = await randomTcpSocket();
|
|
295
|
+
tunnel.socket = socket;
|
|
295
296
|
defineTunnelHandle(tunnel, socket);
|
|
296
297
|
}
|
|
297
298
|
return tunnel;
|
|
@@ -342,12 +343,18 @@ async function defaultTunnel(bind) {
|
|
|
342
343
|
}
|
|
343
344
|
|
|
344
345
|
// Get a listenable ngrok tunnel, suitable for passing to net.Server.listen().
|
|
346
|
+
// Uses the NGROK_AUTHTOKEN environment variable to authenticate.
|
|
345
347
|
async function listenable() {
|
|
346
348
|
return await defaultTunnel();
|
|
347
349
|
}
|
|
348
350
|
|
|
349
|
-
// Bind a server to a ngrok tunnel, optionally passing in a pre-existing tunnel
|
|
351
|
+
// Bind a server to a new ngrok tunnel, optionally passing in a pre-existing tunnel instead.
|
|
352
|
+
// Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
|
|
350
353
|
async function ngrokListen(server, tunnel) {
|
|
354
|
+
if (tunnel && tunnel.socket) {
|
|
355
|
+
// close the default bound port
|
|
356
|
+
tunnel.socket.close();
|
|
357
|
+
}
|
|
351
358
|
if (!tunnel) {
|
|
352
359
|
// turn off automatic bind
|
|
353
360
|
tunnel = await defaultTunnel(false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/ngrok",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -55,19 +55,19 @@
|
|
|
55
55
|
"description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
|
|
56
56
|
"repository": "https://github.com/ngrok/ngrok-js",
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"@ngrok/ngrok-win32-x64-msvc": "0.0.
|
|
59
|
-
"@ngrok/ngrok-darwin-x64": "0.0.
|
|
60
|
-
"@ngrok/ngrok-linux-x64-gnu": "0.0.
|
|
61
|
-
"@ngrok/ngrok-darwin-arm64": "0.0.
|
|
62
|
-
"@ngrok/ngrok-android-arm64": "0.0.
|
|
63
|
-
"@ngrok/ngrok-linux-arm64-gnu": "0.0.
|
|
64
|
-
"@ngrok/ngrok-linux-arm64-musl": "0.0.
|
|
65
|
-
"@ngrok/ngrok-win32-arm64-msvc": "0.0.
|
|
66
|
-
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.
|
|
67
|
-
"@ngrok/ngrok-linux-x64-musl": "0.0.
|
|
68
|
-
"@ngrok/ngrok-freebsd-x64": "0.0.
|
|
69
|
-
"@ngrok/ngrok-win32-ia32-msvc": "0.0.
|
|
70
|
-
"@ngrok/ngrok-android-arm-eabi": "0.0.
|
|
71
|
-
"@ngrok/ngrok-darwin-universal": "0.0.
|
|
58
|
+
"@ngrok/ngrok-win32-x64-msvc": "0.0.12",
|
|
59
|
+
"@ngrok/ngrok-darwin-x64": "0.0.12",
|
|
60
|
+
"@ngrok/ngrok-linux-x64-gnu": "0.0.12",
|
|
61
|
+
"@ngrok/ngrok-darwin-arm64": "0.0.12",
|
|
62
|
+
"@ngrok/ngrok-android-arm64": "0.0.12",
|
|
63
|
+
"@ngrok/ngrok-linux-arm64-gnu": "0.0.12",
|
|
64
|
+
"@ngrok/ngrok-linux-arm64-musl": "0.0.12",
|
|
65
|
+
"@ngrok/ngrok-win32-arm64-msvc": "0.0.12",
|
|
66
|
+
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.12",
|
|
67
|
+
"@ngrok/ngrok-linux-x64-musl": "0.0.12",
|
|
68
|
+
"@ngrok/ngrok-freebsd-x64": "0.0.12",
|
|
69
|
+
"@ngrok/ngrok-win32-ia32-msvc": "0.0.12",
|
|
70
|
+
"@ngrok/ngrok-android-arm-eabi": "0.0.12",
|
|
71
|
+
"@ngrok/ngrok-darwin-universal": "0.0.12"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/session.rs
CHANGED
|
@@ -294,6 +294,16 @@ impl NgrokSession {
|
|
|
294
294
|
}
|
|
295
295
|
res
|
|
296
296
|
}
|
|
297
|
+
|
|
298
|
+
/// Close the ngrok session.
|
|
299
|
+
#[napi]
|
|
300
|
+
pub async fn close(&self) -> Result<()> {
|
|
301
|
+
let mut session = self.raw_session.lock().clone();
|
|
302
|
+
session
|
|
303
|
+
.close()
|
|
304
|
+
.await
|
|
305
|
+
.map_err(|e| napi_err(format!("failed to close tunnel, {e:?}")))
|
|
306
|
+
}
|
|
297
307
|
}
|
|
298
308
|
|
|
299
309
|
impl ObjectFinalize for NgrokSession {
|
package/trailer.js
CHANGED
|
@@ -24,6 +24,7 @@ async function ngrokBind(bind) {
|
|
|
24
24
|
const tunnel = await this._listen();
|
|
25
25
|
if (bind !== false) {
|
|
26
26
|
const socket = await randomTcpSocket();
|
|
27
|
+
tunnel.socket = socket;
|
|
27
28
|
defineTunnelHandle(tunnel, socket);
|
|
28
29
|
}
|
|
29
30
|
return tunnel;
|
|
@@ -74,12 +75,18 @@ async function defaultTunnel(bind) {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
// Get a listenable ngrok tunnel, suitable for passing to net.Server.listen().
|
|
78
|
+
// Uses the NGROK_AUTHTOKEN environment variable to authenticate.
|
|
77
79
|
async function listenable() {
|
|
78
80
|
return await defaultTunnel();
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
// Bind a server to a ngrok tunnel, optionally passing in a pre-existing tunnel
|
|
83
|
+
// Bind a server to a new ngrok tunnel, optionally passing in a pre-existing tunnel instead.
|
|
84
|
+
// Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
|
|
82
85
|
async function ngrokListen(server, tunnel) {
|
|
86
|
+
if (tunnel && tunnel.socket) {
|
|
87
|
+
// close the default bound port
|
|
88
|
+
tunnel.socket.close();
|
|
89
|
+
}
|
|
83
90
|
if (!tunnel) {
|
|
84
91
|
// turn off automatic bind
|
|
85
92
|
tunnel = await defaultTunnel(false);
|