@ngrok/ngrok 0.0.8 → 0.0.10
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 +4 -0
- package/Cargo.toml +2 -2
- package/README.md +21 -0
- package/RELEASE.md +13 -0
- package/examples/ngrok-http-full.js +3 -3
- package/examples/ngrok-labeled.js +1 -1
- package/examples/ngrok-tcp.js +2 -2
- package/examples/ngrok-tls.js +2 -3
- package/examples/ngrok-windows-pipe.js +17 -0
- package/index.d.ts +24 -8
- package/index.js +15 -12
- package/package.json +15 -15
- package/src/session.rs +6 -1
- package/src/tunnel.rs +22 -29
- package/trailer.js +15 -12
package/CHANGELOG.md
CHANGED
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.10"
|
|
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.10.6", default-features = false, features = ["napi4", "tokio_rt"] }
|
|
15
15
|
napi-derive = "2.9.3"
|
|
16
|
-
ngrok = { version = "=0.10.
|
|
16
|
+
ngrok = { version = "=0.10.2" }
|
|
17
17
|
parking_lot = "0.12.1"
|
|
18
18
|
tokio = { version = "1.23.0", features = ["sync"] }
|
|
19
19
|
tracing = "0.1.37"
|
package/README.md
CHANGED
|
@@ -35,6 +35,10 @@ The published library is available on
|
|
|
35
35
|
npm install @ngrok/ngrok
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
# Documentation
|
|
39
|
+
|
|
40
|
+
A quickstart guide and a full API reference are included in the [ngrok-js TypeScript API documentation](https://ngrok.github.io/ngrok-js/).
|
|
41
|
+
|
|
38
42
|
# Quickstart
|
|
39
43
|
|
|
40
44
|
After you've installed the package, you'll need an Auth Token. Retrieve one on the
|
|
@@ -79,6 +83,23 @@ new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
|
|
|
79
83
|
.await;
|
|
80
84
|
```
|
|
81
85
|
|
|
86
|
+
# Platform Support
|
|
87
|
+
|
|
88
|
+
Pre-built binaries are provided on NPM for the following platforms:
|
|
89
|
+
|
|
90
|
+
| OS | i686 | x64 | aarch64 | arm |
|
|
91
|
+
| ---------- | -----|-----|---------|-----|
|
|
92
|
+
| Windows | ✓ | ✓ | * | |
|
|
93
|
+
| MacOS | | ✓ | ✓ | |
|
|
94
|
+
| Linux | | ✓ | ✓ | ✓ |
|
|
95
|
+
| Linux musl | | ✓ | ✓ | |
|
|
96
|
+
| FreeBSD | | ✓ | | |
|
|
97
|
+
| Android | | | ✓ | ✓ |
|
|
98
|
+
|
|
99
|
+
ngrok-js, and [ngrok-rs](https://github.com/ngrok/ngrok-rs/) which it depends on, are open source, so it may be possible to build them for other platforms.
|
|
100
|
+
|
|
101
|
+
* Windows-aarch64 will be supported after the next release of [Ring](https://github.com/briansmith/ring/issues/1167).
|
|
102
|
+
|
|
82
103
|
# Dependencies
|
|
83
104
|
|
|
84
105
|
This project relies on [NAPI-RS](https://napi.rs/), an excellent system to ease development and building of Rust plugins for NodeJS.
|
package/RELEASE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Release Instructions
|
|
2
|
+
--------------------
|
|
3
|
+
1. `git checkout main; git pull origin main`
|
|
4
|
+
1. `git checkout -b <username>/<version>`
|
|
5
|
+
1. Bump patch number in `version` in `Cargo.toml`
|
|
6
|
+
1. `npm version patch --no-commit-hooks --no-git-tag-version`
|
|
7
|
+
1. Verify version numbers all match in `git diff --cached`
|
|
8
|
+
1. `git commit -m '<version>'`
|
|
9
|
+
1. `git push origin <username>/<version>`
|
|
10
|
+
1. Create a pull request off this branch
|
|
11
|
+
- Make sure the name of the pull request is also just the `<version>` so the workflow will know to do a release
|
|
12
|
+
1. Merge the pull request
|
|
13
|
+
1. Verify release appears on [NPM](https://www.npmjs.com/package/@ngrok/ngrok?activeTab=versions)
|
|
@@ -40,10 +40,10 @@ builder.connect().then((session) => {
|
|
|
40
40
|
// .compression()
|
|
41
41
|
// .denyCidr("10.1.1.1/32")
|
|
42
42
|
// .domain("<somedomain>.ngrok.io")
|
|
43
|
-
// .mutualTlsca(fs.readFileSync('
|
|
43
|
+
// .mutualTlsca(fs.readFileSync('ca.crt'))
|
|
44
44
|
// .oauth("google", ["<user>@<domain>"], ["<domain>"], ["<scope>"])
|
|
45
45
|
// .oidc("<url>", "<id>", "<secret>", ["<user>@<domain>"], ["<domain>"], ["<scope>"])
|
|
46
|
-
// .proxyProto("") // One of: "", "
|
|
46
|
+
// .proxyProto("") // One of: "", "1", "2"
|
|
47
47
|
// .removeRequestHeader("X-Req-Nope")
|
|
48
48
|
// .removeResponseHeader("X-Res-Nope")
|
|
49
49
|
// .requestHeader("X-Req-Yup", "true")
|
|
@@ -54,6 +54,6 @@ builder.connect().then((session) => {
|
|
|
54
54
|
.metadata("example tunnel metadata from nodejs")
|
|
55
55
|
.listen().then((tunnel) => {
|
|
56
56
|
console.log("established tunnel at: " + tunnel.url())
|
|
57
|
-
tunnel.
|
|
57
|
+
tunnel.forwardPipe(UNIX_SOCKET);
|
|
58
58
|
})
|
|
59
59
|
});
|
|
@@ -24,6 +24,6 @@ builder.connect().then((session) => {
|
|
|
24
24
|
.metadata("example tunnel metadata from nodejs")
|
|
25
25
|
.listen().then((tunnel) => {
|
|
26
26
|
console.log("established tunnel at: " + JSON.stringify(tunnel.labels()))
|
|
27
|
-
tunnel.
|
|
27
|
+
tunnel.forwardPipe(UNIX_SOCKET);
|
|
28
28
|
})
|
|
29
29
|
});
|
package/examples/ngrok-tcp.js
CHANGED
|
@@ -24,11 +24,11 @@ builder.connect().then((session) => {
|
|
|
24
24
|
// .allowCidr("0.0.0.0/0")
|
|
25
25
|
// .denyCidr("10.1.1.1/32")
|
|
26
26
|
// .forwardsTo("example nodejs")
|
|
27
|
-
// .proxyProto("") // One of: "", "
|
|
27
|
+
// .proxyProto("") // One of: "", "1", "2"
|
|
28
28
|
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
29
29
|
.metadata("example tunnel metadata from nodejs")
|
|
30
30
|
.listen().then((tunnel) => {
|
|
31
31
|
console.log("established tunnel at: " + tunnel.url())
|
|
32
|
-
tunnel.
|
|
32
|
+
tunnel.forwardPipe(UNIX_SOCKET);
|
|
33
33
|
})
|
|
34
34
|
});
|
package/examples/ngrok-tls.js
CHANGED
|
@@ -26,13 +26,12 @@ builder.connect().then((session) => {
|
|
|
26
26
|
// .domain("<somedomain>.ngrok.io")
|
|
27
27
|
// .forwardsTo("example nodejs")
|
|
28
28
|
// .mutualTlsca(fs.readFileSync('ca.crt'))
|
|
29
|
-
// .proxyProto("") // One of: "", "
|
|
30
|
-
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
29
|
+
// .proxyProto("") // One of: "", "1", "2"
|
|
31
30
|
.termination(fs.readFileSync('domain.crt'),
|
|
32
31
|
fs.readFileSync('domain.key'))
|
|
33
32
|
.metadata("example tunnel metadata from nodejs")
|
|
34
33
|
.listen().then((tunnel) => {
|
|
35
34
|
console.log("established tunnel at: " + tunnel.url())
|
|
36
|
-
tunnel.
|
|
35
|
+
tunnel.forwardPipe(UNIX_SOCKET);
|
|
37
36
|
})
|
|
38
37
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const PIPE = '\\\\.\\pipe\\ngrok_pipe';
|
|
2
|
+
|
|
3
|
+
const http = require('http');
|
|
4
|
+
http.createServer(
|
|
5
|
+
function(req,res){res.writeHead(200);
|
|
6
|
+
res.write('Hello');
|
|
7
|
+
res.end();
|
|
8
|
+
} ).listen(PIPE);
|
|
9
|
+
|
|
10
|
+
const ngrok = require('@ngrok/ngrok');
|
|
11
|
+
ngrok.consoleLog(); // turn on debug logging
|
|
12
|
+
new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect().then((session) => {
|
|
13
|
+
session.httpEndpoint().listen().then((tunnel) => {
|
|
14
|
+
console.log('tunnel at: ' + tunnel.url());
|
|
15
|
+
tunnel.forwardPipe(PIPE);
|
|
16
|
+
})
|
|
17
|
+
});
|
package/index.d.ts
CHANGED
|
@@ -152,8 +152,12 @@ export class NgrokHttpTunnel {
|
|
|
152
152
|
metadata(): string
|
|
153
153
|
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
154
154
|
forwardTcp(addr: string): Promise<void>
|
|
155
|
-
/**
|
|
156
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Forward incoming tunnel connections to the provided file socket path.
|
|
157
|
+
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
158
|
+
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
159
|
+
*/
|
|
160
|
+
forwardPipe(addr: string): Promise<void>
|
|
157
161
|
/**
|
|
158
162
|
* Close the tunnel.
|
|
159
163
|
*
|
|
@@ -182,8 +186,12 @@ export class NgrokTcpTunnel {
|
|
|
182
186
|
metadata(): string
|
|
183
187
|
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
184
188
|
forwardTcp(addr: string): Promise<void>
|
|
185
|
-
/**
|
|
186
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Forward incoming tunnel connections to the provided file socket path.
|
|
191
|
+
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
192
|
+
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
193
|
+
*/
|
|
194
|
+
forwardPipe(addr: string): Promise<void>
|
|
187
195
|
/**
|
|
188
196
|
* Close the tunnel.
|
|
189
197
|
*
|
|
@@ -212,8 +220,12 @@ export class NgrokTlsTunnel {
|
|
|
212
220
|
metadata(): string
|
|
213
221
|
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
214
222
|
forwardTcp(addr: string): Promise<void>
|
|
215
|
-
/**
|
|
216
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Forward incoming tunnel connections to the provided file socket path.
|
|
225
|
+
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
226
|
+
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
227
|
+
*/
|
|
228
|
+
forwardPipe(addr: string): Promise<void>
|
|
217
229
|
/**
|
|
218
230
|
* Close the tunnel.
|
|
219
231
|
*
|
|
@@ -240,8 +252,12 @@ export class NgrokLabeledTunnel {
|
|
|
240
252
|
metadata(): string
|
|
241
253
|
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
242
254
|
forwardTcp(addr: string): Promise<void>
|
|
243
|
-
/**
|
|
244
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Forward incoming tunnel connections to the provided file socket path.
|
|
257
|
+
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
258
|
+
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
259
|
+
*/
|
|
260
|
+
forwardPipe(addr: string): Promise<void>
|
|
245
261
|
/**
|
|
246
262
|
* Close the tunnel.
|
|
247
263
|
*
|
package/index.js
CHANGED
|
@@ -325,12 +325,12 @@ function asyncListen(server, options) {
|
|
|
325
325
|
|
|
326
326
|
// Make a session using NGROK_AUTHTOKEN from the environment,
|
|
327
327
|
// and then return a listening HTTP tunnel.
|
|
328
|
-
async function defaultTunnel() {
|
|
328
|
+
async function defaultTunnel(bind) {
|
|
329
329
|
// set up a default session and tunnel
|
|
330
330
|
var builder = new NgrokSessionBuilder();
|
|
331
331
|
builder.authtokenFromEnv();
|
|
332
332
|
var session = await builder.connect();
|
|
333
|
-
var tunnel = await session.httpEndpoint().listen();
|
|
333
|
+
var tunnel = await session.httpEndpoint().listen(bind);
|
|
334
334
|
tunnel.session = session; // surface to caller
|
|
335
335
|
return tunnel;
|
|
336
336
|
}
|
|
@@ -343,15 +343,13 @@ async function listenable() {
|
|
|
343
343
|
// Bind a server to a ngrok tunnel, optionally passing in a pre-existing tunnel
|
|
344
344
|
async function ngrokListen(server, tunnel) {
|
|
345
345
|
if (!tunnel) {
|
|
346
|
-
|
|
346
|
+
// turn off automatic bind
|
|
347
|
+
tunnel = await defaultTunnel(false);
|
|
347
348
|
}
|
|
348
|
-
// todo: abstract socket on linux: https://stackoverflow.com/a/60014174
|
|
349
|
-
// todo: named pipe on windows: https://nodejs.org/api/net.html#ipc-support
|
|
350
349
|
|
|
351
|
-
// attempt
|
|
352
|
-
var socket;
|
|
350
|
+
// attempt pipe socket
|
|
353
351
|
try {
|
|
354
|
-
socket = await
|
|
352
|
+
socket = await ngrokLinkPipe(tunnel, server);
|
|
355
353
|
} catch (err) {
|
|
356
354
|
console.debug("Using TCP socket. " + err);
|
|
357
355
|
// fallback to tcp socket
|
|
@@ -373,8 +371,11 @@ async function ngrokLinkTcp(tunnel, server) {
|
|
|
373
371
|
return socket;
|
|
374
372
|
}
|
|
375
373
|
|
|
376
|
-
async function
|
|
377
|
-
|
|
374
|
+
async function ngrokLinkPipe(tunnel, server) {
|
|
375
|
+
var proposed = "tun-" + tunnel.id() + ".sock";
|
|
376
|
+
if (platform == 'win32') {
|
|
377
|
+
proposed = '\\\\.\\pipe\\' + proposed;
|
|
378
|
+
}
|
|
378
379
|
var filename;
|
|
379
380
|
try {
|
|
380
381
|
fs.accessSync(process.cwd(), fs.constants.W_OK);
|
|
@@ -394,12 +395,14 @@ async function ngrokLinkUnix(tunnel, server) {
|
|
|
394
395
|
const socket = await asyncListen(server, {path: filename});
|
|
395
396
|
// tighten permissions
|
|
396
397
|
try {
|
|
397
|
-
|
|
398
|
+
if (platform != 'win32') {
|
|
399
|
+
fs.chmodSync(filename, fs.constants.S_IRWXU);
|
|
400
|
+
}
|
|
398
401
|
} catch (err) {
|
|
399
402
|
console.debug("Cannot change permissions of file: " + filename);
|
|
400
403
|
}
|
|
401
404
|
// forward tunnel
|
|
402
|
-
tunnel.
|
|
405
|
+
tunnel.forwardPipe(filename);
|
|
403
406
|
socket.path = filename; // surface to caller
|
|
404
407
|
|
|
405
408
|
return socket;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/ngrok",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -54,19 +54,19 @@
|
|
|
54
54
|
"description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
|
|
55
55
|
"repository": "https://github.com/ngrok/ngrok-js",
|
|
56
56
|
"optionalDependencies": {
|
|
57
|
-
"@ngrok/ngrok-win32-x64-msvc": "0.0.
|
|
58
|
-
"@ngrok/ngrok-darwin-x64": "0.0.
|
|
59
|
-
"@ngrok/ngrok-linux-x64-gnu": "0.0.
|
|
60
|
-
"@ngrok/ngrok-darwin-arm64": "0.0.
|
|
61
|
-
"@ngrok/ngrok-android-arm64": "0.0.
|
|
62
|
-
"@ngrok/ngrok-linux-arm64-gnu": "0.0.
|
|
63
|
-
"@ngrok/ngrok-linux-arm64-musl": "0.0.
|
|
64
|
-
"@ngrok/ngrok-win32-arm64-msvc": "0.0.
|
|
65
|
-
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.
|
|
66
|
-
"@ngrok/ngrok-linux-x64-musl": "0.0.
|
|
67
|
-
"@ngrok/ngrok-freebsd-x64": "0.0.
|
|
68
|
-
"@ngrok/ngrok-win32-ia32-msvc": "0.0.
|
|
69
|
-
"@ngrok/ngrok-android-arm-eabi": "0.0.
|
|
70
|
-
"@ngrok/ngrok-darwin-universal": "0.0.
|
|
57
|
+
"@ngrok/ngrok-win32-x64-msvc": "0.0.10",
|
|
58
|
+
"@ngrok/ngrok-darwin-x64": "0.0.10",
|
|
59
|
+
"@ngrok/ngrok-linux-x64-gnu": "0.0.10",
|
|
60
|
+
"@ngrok/ngrok-darwin-arm64": "0.0.10",
|
|
61
|
+
"@ngrok/ngrok-android-arm64": "0.0.10",
|
|
62
|
+
"@ngrok/ngrok-linux-arm64-gnu": "0.0.10",
|
|
63
|
+
"@ngrok/ngrok-linux-arm64-musl": "0.0.10",
|
|
64
|
+
"@ngrok/ngrok-win32-arm64-msvc": "0.0.10",
|
|
65
|
+
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.10",
|
|
66
|
+
"@ngrok/ngrok-linux-x64-musl": "0.0.10",
|
|
67
|
+
"@ngrok/ngrok-freebsd-x64": "0.0.10",
|
|
68
|
+
"@ngrok/ngrok-win32-ia32-msvc": "0.0.10",
|
|
69
|
+
"@ngrok/ngrok-android-arm-eabi": "0.0.10",
|
|
70
|
+
"@ngrok/ngrok-darwin-universal": "0.0.10"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/session.rs
CHANGED
|
@@ -38,6 +38,9 @@ use crate::{
|
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
const CLIENT_TYPE: &str = "library/official/nodejs";
|
|
42
|
+
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
43
|
+
|
|
41
44
|
/// The builder for an ngrok session.
|
|
42
45
|
#[napi]
|
|
43
46
|
#[allow(dead_code)]
|
|
@@ -53,7 +56,9 @@ impl NgrokSessionBuilder {
|
|
|
53
56
|
#[napi(constructor)]
|
|
54
57
|
pub fn new() -> Self {
|
|
55
58
|
NgrokSessionBuilder {
|
|
56
|
-
raw_builder: Arc::new(SyncMutex::new(
|
|
59
|
+
raw_builder: Arc::new(SyncMutex::new(
|
|
60
|
+
Session::builder().child_client(CLIENT_TYPE, VERSION),
|
|
61
|
+
)),
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
|
package/src/tunnel.rs
CHANGED
|
@@ -40,8 +40,7 @@ lazy_static! {
|
|
|
40
40
|
#[async_trait]
|
|
41
41
|
pub trait ExtendedTunnel: Tunnel {
|
|
42
42
|
async fn fwd_tcp(&mut self, addr: String) -> core::result::Result<(), io::Error>;
|
|
43
|
-
|
|
44
|
-
async fn fwd_unix(&mut self, addr: String) -> core::result::Result<(), io::Error>;
|
|
43
|
+
async fn fwd_pipe(&mut self, addr: String) -> core::result::Result<(), io::Error>;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
macro_rules! make_tunnel_type {
|
|
@@ -148,9 +147,8 @@ macro_rules! make_tunnel_type {
|
|
|
148
147
|
async fn fwd_tcp(&mut self, addr: String) -> core::result::Result<(), io::Error> {
|
|
149
148
|
self.forward_tcp(addr).await
|
|
150
149
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
self.forward_unix(addr).await
|
|
150
|
+
async fn fwd_pipe(&mut self, addr: String) -> core::result::Result<(), io::Error> {
|
|
151
|
+
self.forward_pipe(addr).await
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
|
|
@@ -200,32 +198,27 @@ macro_rules! make_tunnel_type {
|
|
|
200
198
|
res
|
|
201
199
|
}
|
|
202
200
|
|
|
203
|
-
/// Forward incoming tunnel connections to the provided
|
|
201
|
+
/// Forward incoming tunnel connections to the provided file socket path.
|
|
202
|
+
/// On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
203
|
+
/// On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
204
204
|
#[napi]
|
|
205
|
-
pub async fn
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
.get(&self.id)
|
|
213
|
-
.ok_or(napi_err("Tunnel is no longer running"))?
|
|
214
|
-
.clone(); // required clone
|
|
205
|
+
pub async fn forward_pipe(&self, addr: String) -> Result<()> {
|
|
206
|
+
// we must clone the Arc before locking so we have a local reference
|
|
207
|
+
// to the mutex to unlock if this struct is dropped.
|
|
208
|
+
let arc = GLOBAL_TUNNELS.lock().await
|
|
209
|
+
.get(&self.id)
|
|
210
|
+
.ok_or(napi_err("Tunnel is no longer running"))?
|
|
211
|
+
.clone(); // required clone
|
|
215
212
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
#[cfg(target_os = "windows")] {
|
|
227
|
-
Err(napi_err(format!("forward_unix not supported on windows")))
|
|
228
|
-
}
|
|
213
|
+
// doing this as a seperate statement so the GLOBAL_TUNNELS lock is dropped
|
|
214
|
+
let res = arc
|
|
215
|
+
.lock()
|
|
216
|
+
.await
|
|
217
|
+
.fwd_pipe(addr)
|
|
218
|
+
.await
|
|
219
|
+
.map_err(|e| napi_err(format!("cannot forward pipe: {e:?}")));
|
|
220
|
+
debug!("forward_pipe returning");
|
|
221
|
+
res
|
|
229
222
|
}
|
|
230
223
|
|
|
231
224
|
/// Close the tunnel.
|
package/trailer.js
CHANGED
|
@@ -63,12 +63,12 @@ function asyncListen(server, options) {
|
|
|
63
63
|
|
|
64
64
|
// Make a session using NGROK_AUTHTOKEN from the environment,
|
|
65
65
|
// and then return a listening HTTP tunnel.
|
|
66
|
-
async function defaultTunnel() {
|
|
66
|
+
async function defaultTunnel(bind) {
|
|
67
67
|
// set up a default session and tunnel
|
|
68
68
|
var builder = new NgrokSessionBuilder();
|
|
69
69
|
builder.authtokenFromEnv();
|
|
70
70
|
var session = await builder.connect();
|
|
71
|
-
var tunnel = await session.httpEndpoint().listen();
|
|
71
|
+
var tunnel = await session.httpEndpoint().listen(bind);
|
|
72
72
|
tunnel.session = session; // surface to caller
|
|
73
73
|
return tunnel;
|
|
74
74
|
}
|
|
@@ -81,15 +81,13 @@ async function listenable() {
|
|
|
81
81
|
// Bind a server to a ngrok tunnel, optionally passing in a pre-existing tunnel
|
|
82
82
|
async function ngrokListen(server, tunnel) {
|
|
83
83
|
if (!tunnel) {
|
|
84
|
-
|
|
84
|
+
// turn off automatic bind
|
|
85
|
+
tunnel = await defaultTunnel(false);
|
|
85
86
|
}
|
|
86
|
-
// todo: abstract socket on linux: https://stackoverflow.com/a/60014174
|
|
87
|
-
// todo: named pipe on windows: https://nodejs.org/api/net.html#ipc-support
|
|
88
87
|
|
|
89
|
-
// attempt
|
|
90
|
-
var socket;
|
|
88
|
+
// attempt pipe socket
|
|
91
89
|
try {
|
|
92
|
-
socket = await
|
|
90
|
+
socket = await ngrokLinkPipe(tunnel, server);
|
|
93
91
|
} catch (err) {
|
|
94
92
|
console.debug("Using TCP socket. " + err);
|
|
95
93
|
// fallback to tcp socket
|
|
@@ -111,8 +109,11 @@ async function ngrokLinkTcp(tunnel, server) {
|
|
|
111
109
|
return socket;
|
|
112
110
|
}
|
|
113
111
|
|
|
114
|
-
async function
|
|
115
|
-
|
|
112
|
+
async function ngrokLinkPipe(tunnel, server) {
|
|
113
|
+
var proposed = "tun-" + tunnel.id() + ".sock";
|
|
114
|
+
if (platform == 'win32') {
|
|
115
|
+
proposed = '\\\\.\\pipe\\' + proposed;
|
|
116
|
+
}
|
|
116
117
|
var filename;
|
|
117
118
|
try {
|
|
118
119
|
fs.accessSync(process.cwd(), fs.constants.W_OK);
|
|
@@ -132,12 +133,14 @@ async function ngrokLinkUnix(tunnel, server) {
|
|
|
132
133
|
const socket = await asyncListen(server, {path: filename});
|
|
133
134
|
// tighten permissions
|
|
134
135
|
try {
|
|
135
|
-
|
|
136
|
+
if (platform != 'win32') {
|
|
137
|
+
fs.chmodSync(filename, fs.constants.S_IRWXU);
|
|
138
|
+
}
|
|
136
139
|
} catch (err) {
|
|
137
140
|
console.debug("Cannot change permissions of file: " + filename);
|
|
138
141
|
}
|
|
139
142
|
// forward tunnel
|
|
140
|
-
tunnel.
|
|
143
|
+
tunnel.forwardPipe(filename);
|
|
141
144
|
socket.path = filename; // surface to caller
|
|
142
145
|
|
|
143
146
|
return socket;
|