@ngrok/ngrok 0.0.6 → 0.0.7
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/Cargo.toml +2 -1
- package/README.md +6 -10
- package/examples/ngrok-get-socket.js +0 -1
- package/examples/ngrok-http-full.js +16 -7
- package/examples/ngrok-http-minimum.js +1 -3
- package/examples/ngrok-labeled.js +2 -4
- package/examples/ngrok-tcp.js +4 -6
- package/examples/ngrok-tls.js +6 -8
- package/examples/ngrok-typescript.ts +43 -0
- package/index.d.ts +108 -24
- package/index.js +13 -11
- package/package.json +21 -17
- package/post-build.js +23 -16
- package/scripts/gc-node-drop.js +38 -0
- package/scripts/gc-rust-drop.js +43 -0
- package/src/lib.rs +9 -0
- package/src/session.rs +217 -31
- package/src/tls.rs +5 -15
- package/src/tunnel.rs +88 -19
- package/src/tunnel_builder.rs +25 -19
- package/trailer.d.ts +2 -0
- package/trailer.js +11 -10
- package/tsconfig.json +6 -0
package/Cargo.toml
CHANGED
|
@@ -8,10 +8,11 @@ crate-type = ["cdylib"]
|
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
10
|
bytes = "1.3.0"
|
|
11
|
+
lazy_static = "1.4.0"
|
|
11
12
|
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
12
13
|
napi = { version = "2.10.6", default-features = false, features = ["napi4", "tokio_rt"] }
|
|
13
14
|
napi-derive = "2.9.3"
|
|
14
|
-
ngrok = { version = "0.
|
|
15
|
+
ngrok = { version = "0.9.0" }
|
|
15
16
|
tokio = { version = "1.23.0", features = ["sync"] }
|
|
16
17
|
tracing = "0.1.37"
|
|
17
18
|
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
package/README.md
CHANGED
|
@@ -44,21 +44,17 @@ There are multiple examples in [the /examples directory](https://github.com/ngro
|
|
|
44
44
|
A minimal use-case looks like the following:
|
|
45
45
|
|
|
46
46
|
```jsx
|
|
47
|
-
require('http').createServer(
|
|
47
|
+
const server = require('http').createServer(
|
|
48
48
|
function(req,res){res.writeHead(200);
|
|
49
49
|
res.write('Hello');
|
|
50
50
|
res.end();
|
|
51
|
-
} )
|
|
51
|
+
} );
|
|
52
52
|
|
|
53
|
-
var t;
|
|
54
53
|
var ngrok = require('@ngrok/ngrok');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
tun.forwardTcp('localhost:8081');
|
|
60
|
-
})
|
|
61
|
-
}).await;
|
|
54
|
+
|
|
55
|
+
ngrok.listen(server).then(() => {
|
|
56
|
+
console.log("url: " + server.tunnel.url());
|
|
57
|
+
});
|
|
62
58
|
```
|
|
63
59
|
|
|
64
60
|
### Async Programming
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
fs.unlinkSync(UNIX_SOCKET)
|
|
3
|
+
try{fs.unlinkSync(UNIX_SOCKET)} catch {}
|
|
4
4
|
|
|
5
5
|
// make webserver
|
|
6
6
|
var http = require('http');
|
|
@@ -14,20 +14,30 @@ console.log('Node.js web server at ' + UNIX_SOCKET + ' is running..');
|
|
|
14
14
|
|
|
15
15
|
// setup ngrok
|
|
16
16
|
var ngrok = require('@ngrok/ngrok');
|
|
17
|
+
// import ngrok from '@ngrok/ngrok' // if inside a module
|
|
17
18
|
builder = new ngrok.NgrokSessionBuilder();
|
|
18
19
|
builder
|
|
19
20
|
// .authtoken("<authtoken>")
|
|
20
21
|
.authtokenFromEnv()
|
|
21
|
-
.metadata("Online in One Line")
|
|
22
|
+
.metadata("Online in One Line")
|
|
23
|
+
.handleStopCommand(() => {
|
|
24
|
+
console.log("stop command");
|
|
25
|
+
})
|
|
26
|
+
.handleRestartCommand(() => {
|
|
27
|
+
console.log("restart command");
|
|
28
|
+
})
|
|
29
|
+
.handleUpdateCommand((update) => {
|
|
30
|
+
console.log("update command, version: " + update.version
|
|
31
|
+
+ " permitMajorVersion: " + update.permitMajorVersion);
|
|
32
|
+
});
|
|
22
33
|
|
|
23
34
|
builder.connect().then((session) => {
|
|
24
|
-
http.ngrok_session = session; // prevent garbage collection
|
|
25
35
|
session.httpEndpoint()
|
|
26
|
-
// .
|
|
36
|
+
// .allowCidr("0.0.0.0/0")
|
|
27
37
|
// .basicAuth("ngrok", "online1line")
|
|
28
38
|
// .circuitBreaker(0.5)
|
|
29
39
|
// .compression()
|
|
30
|
-
// .
|
|
40
|
+
// .denyCidr("10.1.1.1/32")
|
|
31
41
|
// .domain("<somedomain>.ngrok.io")
|
|
32
42
|
// .mutualTlsca(fs.readFileSync('domain.crt'))
|
|
33
43
|
// .oauth("google", ["<user>@<domain>"], ["<domain>"], ["<scope>"])
|
|
@@ -42,8 +52,7 @@ builder.connect().then((session) => {
|
|
|
42
52
|
// .webhookVerification("twilio", "asdf"),
|
|
43
53
|
.metadata("example tunnel metadata from nodejs")
|
|
44
54
|
.listen().then((tunnel) => {
|
|
45
|
-
http.tunnel = tunnel; // prevent garbage collection
|
|
46
55
|
console.log("established tunnel at: " + tunnel.url())
|
|
47
56
|
tunnel.forwardUnix(UNIX_SOCKET);
|
|
48
57
|
})
|
|
49
|
-
})
|
|
58
|
+
});
|
|
@@ -7,10 +7,8 @@ http.createServer(
|
|
|
7
7
|
|
|
8
8
|
var ngrok = require('@ngrok/ngrok');
|
|
9
9
|
new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect().then((session) => {
|
|
10
|
-
http.ngrok_session = session; // prevent garbage collection
|
|
11
10
|
session.httpEndpoint().listen().then((tunnel) => {
|
|
12
|
-
http.tunnel = tunnel; // prevent garbage collection
|
|
13
11
|
console.log('tunnel at: ' + tunnel.url());
|
|
14
12
|
tunnel.forwardTcp('localhost:8081');
|
|
15
13
|
})
|
|
16
|
-
})
|
|
14
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
fs.unlinkSync(UNIX_SOCKET)
|
|
3
|
+
try{fs.unlinkSync(UNIX_SOCKET)} catch {}
|
|
4
4
|
|
|
5
5
|
// make webserver
|
|
6
6
|
var http = require('http');
|
|
@@ -19,13 +19,11 @@ builder.authtokenFromEnv()
|
|
|
19
19
|
.metadata("Online in One Line");
|
|
20
20
|
|
|
21
21
|
builder.connect().then((session) => {
|
|
22
|
-
http.ngrok_session = session; // prevent garbage collection
|
|
23
22
|
session.labeledTunnel()
|
|
24
23
|
.label("edge", "edghts_<edge_id>")
|
|
25
24
|
.metadata("example tunnel metadata from nodejs")
|
|
26
25
|
.listen().then((tunnel) => {
|
|
27
|
-
http.tunnel = tunnel; // prevent garbage collection
|
|
28
26
|
console.log("established tunnel at: " + JSON.stringify(tunnel.labels()))
|
|
29
27
|
tunnel.forwardUnix(UNIX_SOCKET);
|
|
30
28
|
})
|
|
31
|
-
})
|
|
29
|
+
});
|
package/examples/ngrok-tcp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
fs.unlinkSync(UNIX_SOCKET)
|
|
3
|
+
try{fs.unlinkSync(UNIX_SOCKET)} catch {}
|
|
4
4
|
|
|
5
5
|
// make webserver
|
|
6
6
|
var http = require('http');
|
|
@@ -20,17 +20,15 @@ builder.authtokenFromEnv()
|
|
|
20
20
|
|
|
21
21
|
var global_tunnel;
|
|
22
22
|
builder.connect().then((session) => {
|
|
23
|
-
http.ngrok_session = session; // prevent garbage collection
|
|
24
23
|
session.tcpEndpoint()
|
|
25
|
-
// .
|
|
26
|
-
// .
|
|
24
|
+
// .allowCidr("0.0.0.0/0")
|
|
25
|
+
// .denyCidr("10.1.1.1/32")
|
|
27
26
|
// .forwardsTo("example nodejs")
|
|
28
27
|
// .proxyProto("") // One of: "", "V1", "V2"
|
|
29
28
|
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
30
29
|
.metadata("example tunnel metadata from nodejs")
|
|
31
30
|
.listen().then((tunnel) => {
|
|
32
|
-
http.tunnel = tunnel; // prevent garbage collection
|
|
33
31
|
console.log("established tunnel at: " + tunnel.url())
|
|
34
32
|
tunnel.forwardUnix(UNIX_SOCKET);
|
|
35
33
|
})
|
|
36
|
-
})
|
|
34
|
+
});
|
package/examples/ngrok-tls.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var UNIX_SOCKET = "/tmp/http.socket";
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
fs.unlinkSync(UNIX_SOCKET)
|
|
3
|
+
try{fs.unlinkSync(UNIX_SOCKET)} catch {}
|
|
4
4
|
|
|
5
5
|
// make webserver
|
|
6
6
|
var http = require('http');
|
|
@@ -19,22 +19,20 @@ builder.authtokenFromEnv()
|
|
|
19
19
|
.metadata("Online in One Line");
|
|
20
20
|
|
|
21
21
|
builder.connect().then((session) => {
|
|
22
|
-
http.ngrok_session = session; // prevent garbage collection
|
|
23
22
|
console.log("established session");
|
|
24
23
|
session.tlsEndpoint()
|
|
25
|
-
// .
|
|
26
|
-
// .
|
|
24
|
+
// .allowCidr("0.0.0.0/0")
|
|
25
|
+
// .denyCidr("10.1.1.1/32")
|
|
27
26
|
// .domain("<somedomain>.ngrok.io")
|
|
28
27
|
// .forwardsTo("example nodejs")
|
|
29
28
|
// .mutualTlsca(fs.readFileSync('ca.crt'))
|
|
30
29
|
// .proxyProto("") // One of: "", "V1", "V2"
|
|
31
30
|
// .remoteAddr("<n>.tcp.ngrok.io:<p>")
|
|
32
|
-
.
|
|
33
|
-
|
|
31
|
+
.termination(fs.readFileSync('domain.crt'),
|
|
32
|
+
fs.readFileSync('domain.key'))
|
|
34
33
|
.metadata("example tunnel metadata from nodejs")
|
|
35
34
|
.listen().then((tunnel) => {
|
|
36
|
-
http.tunnel = tunnel; // prevent garbage collection
|
|
37
35
|
console.log("established tunnel at: " + tunnel.url())
|
|
38
36
|
tunnel.forwardUnix(UNIX_SOCKET);
|
|
39
37
|
})
|
|
40
|
-
})
|
|
38
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Run with 'ts-node examples/ngrok-typescript.ts'
|
|
2
|
+
|
|
3
|
+
import * as http from "http";
|
|
4
|
+
const httpServer = http.createServer(
|
|
5
|
+
function(req,res){res.writeHead(200);
|
|
6
|
+
res.write('Hello');
|
|
7
|
+
res.end();
|
|
8
|
+
} )
|
|
9
|
+
.listen(8081);
|
|
10
|
+
|
|
11
|
+
import * as ngrok from "../index";
|
|
12
|
+
|
|
13
|
+
const run = async (): Promise<void> => {
|
|
14
|
+
/*
|
|
15
|
+
const tunnel = await ngrok.listen(httpServer);
|
|
16
|
+
if ( typeof tunnel['url'] === 'function') {
|
|
17
|
+
console.log("tunnel at: " + tunnel['url']());
|
|
18
|
+
}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
const socket = await ngrok.getSocket();
|
|
23
|
+
httpServer.listen(socket);
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const sessionBuilder = new ngrok.NgrokSessionBuilder().authtokenFromEnv()
|
|
27
|
+
.handleStopCommand(() => {
|
|
28
|
+
console.log("stop command");
|
|
29
|
+
})
|
|
30
|
+
.handleRestartCommand(() => {
|
|
31
|
+
console.log("restart command");
|
|
32
|
+
})
|
|
33
|
+
.handleUpdateCommand((update) => {
|
|
34
|
+
console.log("update command, version: " + update.version
|
|
35
|
+
+ " permitMajorVersion: " + update.permitMajorVersion);
|
|
36
|
+
});
|
|
37
|
+
const session = await sessionBuilder.connect();
|
|
38
|
+
const tunnel = await session.httpEndpoint().listen();
|
|
39
|
+
console.log('tunnel at: ' + tunnel.url());
|
|
40
|
+
tunnel.forwardTcp('localhost:8081');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
run();
|
package/index.d.ts
CHANGED
|
@@ -13,32 +13,104 @@ export function tracingSubscriber(): void
|
|
|
13
13
|
export class NgrokSessionBuilder {
|
|
14
14
|
/** Create a new session builder */
|
|
15
15
|
constructor()
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Configures the session to authenticate with the provided authtoken. You
|
|
18
|
+
* can [find your existing authtoken] or [create a new one] in the ngrok
|
|
19
|
+
* dashboard.
|
|
20
|
+
*
|
|
21
|
+
* See the [authtoken parameter in the ngrok docs] for additional details.
|
|
22
|
+
*
|
|
23
|
+
* [find your existing authtoken]: https://dashboard.ngrok.com/get-started/your-authtoken
|
|
24
|
+
* [create a new one]: https://dashboard.ngrok.com/tunnels/authtokens
|
|
25
|
+
* [authtoken parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#authtoken
|
|
26
|
+
*/
|
|
17
27
|
authtoken(authtoken: string): this
|
|
18
28
|
/**
|
|
19
|
-
*
|
|
20
|
-
* variable.
|
|
29
|
+
* Shortcut for calling [SessionBuilder::authtoken] with the value of the
|
|
30
|
+
* NGROK_AUTHTOKEN environment variable.
|
|
21
31
|
*/
|
|
22
32
|
authtokenFromEnv(): this
|
|
23
33
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
34
|
+
* Configures how often the session will send heartbeat messages to the ngrok
|
|
35
|
+
* service to check session liveness.
|
|
36
|
+
*
|
|
37
|
+
* See the [heartbeat_interval parameter in the ngrok docs] for additional
|
|
38
|
+
* details.
|
|
39
|
+
*
|
|
40
|
+
* [heartbeat_interval parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_interval
|
|
27
41
|
*/
|
|
28
42
|
heartbeatInterval(heartbeatInterval: number): this
|
|
29
43
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
44
|
+
* Configures the duration to wait for a response to a heartbeat before
|
|
45
|
+
* assuming the session connection is dead and attempting to reconnect.
|
|
46
|
+
*
|
|
47
|
+
* See the [heartbeat_tolerance parameter in the ngrok docs] for additional
|
|
48
|
+
* details.
|
|
49
|
+
*
|
|
50
|
+
* [heartbeat_tolerance parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_tolerance
|
|
33
51
|
*/
|
|
34
52
|
heartbeatTolerance(heartbeatTolerance: number): this
|
|
35
53
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
54
|
+
* Configures the opaque, machine-readable metadata string for this session.
|
|
55
|
+
* Metadata is made available to you in the ngrok dashboard and the Agents API
|
|
56
|
+
* resource. It is a useful way to allow you to uniquely identify sessions. We
|
|
57
|
+
* suggest encoding the value in a structured format like JSON.
|
|
58
|
+
*
|
|
59
|
+
* See the [metdata parameter in the ngrok docs] for additional details.
|
|
60
|
+
*
|
|
61
|
+
* [metdata parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#metadata
|
|
38
62
|
*/
|
|
39
63
|
metadata(metadata: string): this
|
|
40
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Configures the network address to dial to connect to the ngrok service.
|
|
66
|
+
* Use this option only if you are connecting to a custom agent ingress.
|
|
67
|
+
*
|
|
68
|
+
* See the [server_addr parameter in the ngrok docs] for additional details.
|
|
69
|
+
*
|
|
70
|
+
* [server_addr parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#server_addr
|
|
71
|
+
*/
|
|
41
72
|
serverAddr(addr: string): this
|
|
73
|
+
/**
|
|
74
|
+
* Configures a function which is called when the ngrok service requests that
|
|
75
|
+
* this [Session] stops. Your application may choose to interpret this callback
|
|
76
|
+
* as a request to terminate the [Session] or the entire process.
|
|
77
|
+
*
|
|
78
|
+
* Errors returned by this function will be visible to the ngrok dashboard or
|
|
79
|
+
* API as the response to the Stop operation.
|
|
80
|
+
*
|
|
81
|
+
* Do not block inside this callback. It will cause the Dashboard or API
|
|
82
|
+
* stop operation to time out. Do not call [std::process::exit] inside this
|
|
83
|
+
* callback, it will also cause the operation to time out.
|
|
84
|
+
*/
|
|
85
|
+
handleStopCommand(handler: () => void): this
|
|
86
|
+
/**
|
|
87
|
+
* Configures a function which is called when the ngrok service requests
|
|
88
|
+
* that this [Session] updates. Your application may choose to interpret
|
|
89
|
+
* this callback as a request to restart the [Session] or the entire
|
|
90
|
+
* process.
|
|
91
|
+
*
|
|
92
|
+
* Errors returned by this function will be visible to the ngrok dashboard or
|
|
93
|
+
* API as the response to the Restart operation.
|
|
94
|
+
*
|
|
95
|
+
* Do not block inside this callback. It will cause the Dashboard or API
|
|
96
|
+
* stop operation to time out. Do not call [std::process::exit] inside this
|
|
97
|
+
* callback, it will also cause the operation to time out.
|
|
98
|
+
*/
|
|
99
|
+
handleRestartCommand(handler: () => void): this
|
|
100
|
+
/**
|
|
101
|
+
* Configures a function which is called when the ngrok service requests
|
|
102
|
+
* that this [Session] updates. Your application may choose to interpret
|
|
103
|
+
* this callback as a request to update its configuration, itself, or to
|
|
104
|
+
* invoke some other application-specific behavior.
|
|
105
|
+
*
|
|
106
|
+
* Errors returned by this function will be visible to the ngrok dashboard or
|
|
107
|
+
* API as the response to the Restart operation.
|
|
108
|
+
*
|
|
109
|
+
* Do not block inside this callback. It will cause the Dashboard or API
|
|
110
|
+
* stop operation to time out. Do not call [std::process::exit] inside this
|
|
111
|
+
* callback, it will also cause the operation to time out.
|
|
112
|
+
*/
|
|
113
|
+
handleUpdateCommand(handler: (update: UpdateRequest) => void): this
|
|
42
114
|
/** Attempt to establish an ngrok session using the current configuration. */
|
|
43
115
|
connect(): Promise<NgrokSession>
|
|
44
116
|
}
|
|
@@ -52,6 +124,13 @@ export class NgrokSession {
|
|
|
52
124
|
tlsEndpoint(): NgrokTlsTunnelBuilder
|
|
53
125
|
/** Start building a labeled tunnel. */
|
|
54
126
|
labeledTunnel(): NgrokLabeledTunnelBuilder
|
|
127
|
+
closeTunnel(id: string): Promise<void>
|
|
128
|
+
}
|
|
129
|
+
export class UpdateRequest {
|
|
130
|
+
/** The version that the agent is requested to update to. */
|
|
131
|
+
version: string
|
|
132
|
+
/** Whether or not updating to the same major version is sufficient. */
|
|
133
|
+
permitMajorVersion: boolean
|
|
55
134
|
}
|
|
56
135
|
/**r" An ngrok tunnel backing an HTTP endpoint. */
|
|
57
136
|
export class NgrokHttpTunnel {
|
|
@@ -65,6 +144,8 @@ export class NgrokHttpTunnel {
|
|
|
65
144
|
forwardTcp(addr: string): Promise<void>
|
|
66
145
|
/** Forward incoming tunnel connections to the provided Unix socket path. */
|
|
67
146
|
forwardUnix(addr: string): Promise<void>
|
|
147
|
+
/** Close the tunnel. */
|
|
148
|
+
close(): Promise<void>
|
|
68
149
|
}
|
|
69
150
|
/**r" An ngrok tunnel backing a TCP endpoint. */
|
|
70
151
|
export class NgrokTcpTunnel {
|
|
@@ -78,6 +159,8 @@ export class NgrokTcpTunnel {
|
|
|
78
159
|
forwardTcp(addr: string): Promise<void>
|
|
79
160
|
/** Forward incoming tunnel connections to the provided Unix socket path. */
|
|
80
161
|
forwardUnix(addr: string): Promise<void>
|
|
162
|
+
/** Close the tunnel. */
|
|
163
|
+
close(): Promise<void>
|
|
81
164
|
}
|
|
82
165
|
/**r" An ngrok tunnel bcking a TLS endpoint. */
|
|
83
166
|
export class NgrokTlsTunnel {
|
|
@@ -91,6 +174,8 @@ export class NgrokTlsTunnel {
|
|
|
91
174
|
forwardTcp(addr: string): Promise<void>
|
|
92
175
|
/** Forward incoming tunnel connections to the provided Unix socket path. */
|
|
93
176
|
forwardUnix(addr: string): Promise<void>
|
|
177
|
+
/** Close the tunnel. */
|
|
178
|
+
close(): Promise<void>
|
|
94
179
|
}
|
|
95
180
|
/**r" A labeled ngrok tunnel. */
|
|
96
181
|
export class NgrokLabeledTunnel {
|
|
@@ -102,6 +187,8 @@ export class NgrokLabeledTunnel {
|
|
|
102
187
|
forwardTcp(addr: string): Promise<void>
|
|
103
188
|
/** Forward incoming tunnel connections to the provided Unix socket path. */
|
|
104
189
|
forwardUnix(addr: string): Promise<void>
|
|
190
|
+
/** Close the tunnel. */
|
|
191
|
+
close(): Promise<void>
|
|
105
192
|
}
|
|
106
193
|
/**r" An ngrok tunnel backing an HTTP endpoint. */
|
|
107
194
|
export class NgrokHttpTunnelBuilder {
|
|
@@ -159,12 +246,12 @@ export class NgrokHttpTunnelBuilder {
|
|
|
159
246
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
160
247
|
* Call multiple times to add additional CIDR ranges.
|
|
161
248
|
*/
|
|
162
|
-
|
|
249
|
+
allowCidr(cidr: string): this
|
|
163
250
|
/**
|
|
164
251
|
* Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges.
|
|
165
252
|
* Call multiple times to add additional CIDR ranges.
|
|
166
253
|
*/
|
|
167
|
-
|
|
254
|
+
denyCidr(cidr: string): this
|
|
168
255
|
/** The version of PROXY protocol to use with this tunnel, None if not using. */
|
|
169
256
|
proxyProto(proxyProto: string): this
|
|
170
257
|
/**
|
|
@@ -185,12 +272,12 @@ export class NgrokTcpTunnelBuilder {
|
|
|
185
272
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
186
273
|
* Call multiple times to add additional CIDR ranges.
|
|
187
274
|
*/
|
|
188
|
-
|
|
275
|
+
allowCidr(cidr: string): this
|
|
189
276
|
/**
|
|
190
277
|
* Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges.
|
|
191
278
|
* Call multiple times to add additional CIDR ranges.
|
|
192
279
|
*/
|
|
193
|
-
|
|
280
|
+
denyCidr(cidr: string): this
|
|
194
281
|
/** The version of PROXY protocol to use with this tunnel, None if not using. */
|
|
195
282
|
proxyProto(proxyProto: string): this
|
|
196
283
|
/**
|
|
@@ -206,12 +293,7 @@ export class NgrokTlsTunnelBuilder {
|
|
|
206
293
|
/** Certificates to use for client authentication at the ngrok edge. */
|
|
207
294
|
mutualTlsca(mutualTlsca: Uint8Array): this
|
|
208
295
|
/** The key to use for TLS termination at the ngrok edge in PEM format. */
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* The certificate to use for TLS termination at the ngrok edge in PEM
|
|
212
|
-
* format.
|
|
213
|
-
*/
|
|
214
|
-
certPem(certPem: Uint8Array): this
|
|
296
|
+
termination(certPem: Uint8Array, keyPem: Uint8Array): this
|
|
215
297
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
216
298
|
metadata(metadata: string): this
|
|
217
299
|
/** Begin listening for new connections on this tunnel. */
|
|
@@ -220,12 +302,12 @@ export class NgrokTlsTunnelBuilder {
|
|
|
220
302
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
221
303
|
* Call multiple times to add additional CIDR ranges.
|
|
222
304
|
*/
|
|
223
|
-
|
|
305
|
+
allowCidr(cidr: string): this
|
|
224
306
|
/**
|
|
225
307
|
* Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges.
|
|
226
308
|
* Call multiple times to add additional CIDR ranges.
|
|
227
309
|
*/
|
|
228
|
-
|
|
310
|
+
denyCidr(cidr: string): this
|
|
229
311
|
/** The version of PROXY protocol to use with this tunnel, None if not using. */
|
|
230
312
|
proxyProto(proxyProto: string): this
|
|
231
313
|
/**
|
|
@@ -243,3 +325,5 @@ export class NgrokLabeledTunnelBuilder {
|
|
|
243
325
|
/** Add a label, value pair for this tunnel. */
|
|
244
326
|
label(label: string, value: string): this
|
|
245
327
|
}
|
|
328
|
+
export function getSocket(tunnel?: (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)): net.Server
|
|
329
|
+
export function listen(server: net.Server, tunnel?: (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)): (NgrokHttpTunnel|NgrokTcpTunnel|NgrokTlsTunnel|NgrokLabeledTunnel)
|
package/index.js
CHANGED
|
@@ -246,11 +246,12 @@ if (!nativeBinding) {
|
|
|
246
246
|
throw new Error(`Failed to load native binding`)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
const { NgrokSessionBuilder, tracingSubscriber, NgrokSession, NgrokHttpTunnel, NgrokTcpTunnel, NgrokTlsTunnel, NgrokLabeledTunnel, NgrokHttpTunnelBuilder, NgrokTcpTunnelBuilder, NgrokTlsTunnelBuilder, NgrokLabeledTunnelBuilder } = nativeBinding
|
|
249
|
+
const { NgrokSessionBuilder, tracingSubscriber, NgrokSession, UpdateRequest, NgrokHttpTunnel, NgrokTcpTunnel, NgrokTlsTunnel, NgrokLabeledTunnel, NgrokHttpTunnelBuilder, NgrokTcpTunnelBuilder, NgrokTlsTunnelBuilder, NgrokLabeledTunnelBuilder } = nativeBinding
|
|
250
250
|
|
|
251
251
|
module.exports.NgrokSessionBuilder = NgrokSessionBuilder
|
|
252
252
|
module.exports.tracingSubscriber = tracingSubscriber
|
|
253
253
|
module.exports.NgrokSession = NgrokSession
|
|
254
|
+
module.exports.UpdateRequest = UpdateRequest
|
|
254
255
|
module.exports.NgrokHttpTunnel = NgrokHttpTunnel
|
|
255
256
|
module.exports.NgrokTcpTunnel = NgrokTcpTunnel
|
|
256
257
|
module.exports.NgrokTlsTunnel = NgrokTlsTunnel
|
|
@@ -284,7 +285,7 @@ async function getSocket(tunnel) {
|
|
|
284
285
|
}
|
|
285
286
|
// use tcp socket with random local port
|
|
286
287
|
const server = new net.Server();
|
|
287
|
-
server.listen(0);
|
|
288
|
+
await server.listen(0);
|
|
288
289
|
// forward to this socket
|
|
289
290
|
tunnel.forwardTcp('localhost:' + server.address().port);
|
|
290
291
|
// surface to caller
|
|
@@ -301,20 +302,21 @@ async function ngrokListen(server, tunnel) {
|
|
|
301
302
|
// todo: named pipe on windows: https://nodejs.org/api/net.html#ipc-support
|
|
302
303
|
|
|
303
304
|
// attempt unix socket
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
305
|
+
try {
|
|
306
|
+
await ngrokLinkUnix(tunnel, server);
|
|
307
|
+
} catch (err) {
|
|
308
|
+
console.debug("Using TCP socket. " + err);
|
|
309
|
+
// fallback to tcp socket
|
|
310
|
+
await ngrokLinkTcp(tunnel, server);
|
|
311
|
+
}
|
|
311
312
|
|
|
312
313
|
server.tunnel = tunnel; // surface to caller
|
|
314
|
+
return tunnel;
|
|
313
315
|
}
|
|
314
316
|
|
|
315
317
|
async function ngrokLinkTcp(tunnel, server) {
|
|
316
318
|
// random local port
|
|
317
|
-
server.listen(0);
|
|
319
|
+
await server.listen(0);
|
|
318
320
|
// forward to socket
|
|
319
321
|
tunnel.forwardTcp('localhost:' + server.address().port);
|
|
320
322
|
}
|
|
@@ -337,7 +339,7 @@ async function ngrokLinkUnix(tunnel, server) {
|
|
|
337
339
|
}
|
|
338
340
|
|
|
339
341
|
// begin listening
|
|
340
|
-
server.listen({path: filename});
|
|
342
|
+
await server.listen({path: filename});
|
|
341
343
|
// tighten permissions
|
|
342
344
|
try {
|
|
343
345
|
fs.chmodSync(filename, fs.constants.S_IRWXU);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/ngrok",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -24,8 +24,12 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@napi-rs/cli": "^2.14.1",
|
|
27
|
+
"@types/node": "^18.13.0",
|
|
27
28
|
"ava": "^4.3.3",
|
|
28
|
-
"express": "^4.18.2"
|
|
29
|
+
"express": "^4.18.2",
|
|
30
|
+
"segfault-handler": "^1.3.0",
|
|
31
|
+
"ts-node": "^10.9.1",
|
|
32
|
+
"typescript": "^4.9.5"
|
|
29
33
|
},
|
|
30
34
|
"ava": {
|
|
31
35
|
"timeout": "3m"
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
},
|
|
36
40
|
"scripts": {
|
|
37
41
|
"artifacts": "napi artifacts",
|
|
38
|
-
"build": "napi build --platform --release --js gen.js --pipe 'node post-build.js trailer index'",
|
|
42
|
+
"build": "napi build --platform --release --js gen.js --dts gen.d.ts --pipe 'node post-build.js trailer index'",
|
|
39
43
|
"build:debug": "napi build --platform",
|
|
40
44
|
"prepublishOnly": "napi prepublish -t npm",
|
|
41
45
|
"test": "ava",
|
|
@@ -46,19 +50,19 @@
|
|
|
46
50
|
"description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
|
|
47
51
|
"repository": "https://github.com/ngrok/ngrok-js",
|
|
48
52
|
"optionalDependencies": {
|
|
49
|
-
"@ngrok/ngrok-win32-x64-msvc": "0.0.
|
|
50
|
-
"@ngrok/ngrok-darwin-x64": "0.0.
|
|
51
|
-
"@ngrok/ngrok-linux-x64-gnu": "0.0.
|
|
52
|
-
"@ngrok/ngrok-darwin-arm64": "0.0.
|
|
53
|
-
"@ngrok/ngrok-android-arm64": "0.0.
|
|
54
|
-
"@ngrok/ngrok-linux-arm64-gnu": "0.0.
|
|
55
|
-
"@ngrok/ngrok-linux-arm64-musl": "0.0.
|
|
56
|
-
"@ngrok/ngrok-win32-arm64-msvc": "0.0.
|
|
57
|
-
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.
|
|
58
|
-
"@ngrok/ngrok-linux-x64-musl": "0.0.
|
|
59
|
-
"@ngrok/ngrok-freebsd-x64": "0.0.
|
|
60
|
-
"@ngrok/ngrok-win32-ia32-msvc": "0.0.
|
|
61
|
-
"@ngrok/ngrok-android-arm-eabi": "0.0.
|
|
62
|
-
"@ngrok/ngrok-darwin-universal": "0.0.
|
|
53
|
+
"@ngrok/ngrok-win32-x64-msvc": "0.0.7",
|
|
54
|
+
"@ngrok/ngrok-darwin-x64": "0.0.7",
|
|
55
|
+
"@ngrok/ngrok-linux-x64-gnu": "0.0.7",
|
|
56
|
+
"@ngrok/ngrok-darwin-arm64": "0.0.7",
|
|
57
|
+
"@ngrok/ngrok-android-arm64": "0.0.7",
|
|
58
|
+
"@ngrok/ngrok-linux-arm64-gnu": "0.0.7",
|
|
59
|
+
"@ngrok/ngrok-linux-arm64-musl": "0.0.7",
|
|
60
|
+
"@ngrok/ngrok-win32-arm64-msvc": "0.0.7",
|
|
61
|
+
"@ngrok/ngrok-linux-arm-gnueabihf": "0.0.7",
|
|
62
|
+
"@ngrok/ngrok-linux-x64-musl": "0.0.7",
|
|
63
|
+
"@ngrok/ngrok-freebsd-x64": "0.0.7",
|
|
64
|
+
"@ngrok/ngrok-win32-ia32-msvc": "0.0.7",
|
|
65
|
+
"@ngrok/ngrok-android-arm-eabi": "0.0.7",
|
|
66
|
+
"@ngrok/ngrok-darwin-universal": "0.0.7"
|
|
63
67
|
}
|
|
64
68
|
}
|
package/post-build.js
CHANGED
|
@@ -7,25 +7,32 @@ var trailer_prefix = args[0];
|
|
|
7
7
|
var output_prefix = args[1];
|
|
8
8
|
var input_path = args[2];
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// skipping the typescript file since it actually isn't written before the call to pipe:
|
|
11
|
+
// https://github.com/napi-rs/napi-rs/issues/1188
|
|
11
12
|
if (input_path.endsWith('.d.ts')) {
|
|
12
13
|
console.log("skipping .d.ts file: " + input_path);
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
input_filename = path.basename(input_path);
|
|
20
|
-
input_suffix = input_filename.substring(input_filename.indexOf('.'), input_filename.length);
|
|
21
|
-
output_filename = output_prefix + input_suffix
|
|
17
|
+
// run for .js and .d.ts
|
|
18
|
+
concat_files(trailer_prefix, output_prefix, input_path);
|
|
19
|
+
concat_files(trailer_prefix, output_prefix, input_path.replace(/\.js/, ".d.ts"));
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.log("
|
|
21
|
+
function concat_files (trailer_prefix, output_prefix, input_path) {
|
|
22
|
+
console.log("trailer_prefix: '" + trailer_prefix + "' output_prefix: '" + output_prefix
|
|
23
|
+
+ "' input_path: '" + input_path + "'");
|
|
24
|
+
path = require("path");
|
|
25
|
+
input_filename = path.basename(input_path);
|
|
26
|
+
input_suffix = input_filename.substring(input_filename.indexOf('.'), input_filename.length);
|
|
27
|
+
output_filename = output_prefix + input_suffix;
|
|
28
|
+
|
|
29
|
+
console.log("writing: " + output_filename);
|
|
30
|
+
var fs = require('fs');
|
|
31
|
+
// input to output
|
|
32
|
+
var data = fs.readFileSync(input_path, 'utf8');
|
|
33
|
+
fs.writeFileSync(output_filename, data, {encoding: 'utf8', flag: 'w'});
|
|
34
|
+
// trailer to output
|
|
35
|
+
data = fs.readFileSync(trailer_prefix + input_suffix, 'utf8');
|
|
36
|
+
fs.writeFileSync(output_filename, data, {encoding: 'utf8', flag: 'a'});
|
|
37
|
+
console.log("post-build complete");
|
|
38
|
+
}
|