@dpkrn/nodetunnel 1.0.6 β 1.0.8
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/cmd/test-lib/main.js +0 -2
- package/internal/tunnel/tunnel.js +10 -0
- package/package.json +1 -1
- package/pkg/tunnel/tunnel.js +24 -3
package/cmd/test-lib/main.js
CHANGED
|
@@ -28,10 +28,8 @@ app.get("/", async (req, res) => {
|
|
|
28
28
|
|
|
29
29
|
app.listen(PORT, async () => {
|
|
30
30
|
console.log(`listening on http://127.0.0.1:${PORT}`);
|
|
31
|
-
console.log("Leave this terminal open; press Ctrl+C to stop.");
|
|
32
31
|
try {
|
|
33
32
|
const { url, stop } = await startTunnel(String(PORT));
|
|
34
|
-
console.log("π Public URL:", url);
|
|
35
33
|
process.once("SIGINT", () => {
|
|
36
34
|
stop();
|
|
37
35
|
process.exit(0);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import net from 'node:net';
|
|
2
3
|
import { Session } from 'yamux-js/lib/session.js';
|
|
4
|
+
// import { version } from '../../../package.json' with { type: 'json' };
|
|
3
5
|
|
|
4
6
|
const defaultMuxConfig = {
|
|
5
7
|
enableKeepAlive: false,
|
|
@@ -180,6 +182,14 @@ class Tunnel {
|
|
|
180
182
|
socket.once('error', reject);
|
|
181
183
|
});
|
|
182
184
|
|
|
185
|
+
// Client hello (JSON line). Match Go json.Marshal(ClientHello) with exported fields (PascalCase).
|
|
186
|
+
socket.write(JSON.stringify({
|
|
187
|
+
tunnel_type: 'nodetunnel',
|
|
188
|
+
Version: "1.0.7",
|
|
189
|
+
tunnel_id: 'fixed_id',
|
|
190
|
+
connection_id: "conn_"+randomUUID(),
|
|
191
|
+
}) + '\n');
|
|
192
|
+
|
|
183
193
|
const { line, remainder } = await readPublicUrlLine(socket);
|
|
184
194
|
this.publicUrl = `${line}`;
|
|
185
195
|
|
package/package.json
CHANGED
package/pkg/tunnel/tunnel.js
CHANGED
|
@@ -20,7 +20,26 @@
|
|
|
20
20
|
import { newTunnel } from '../../internal/tunnel/tunnel.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Print a formatted success message for the tunnel.
|
|
24
|
+
* @param {string} publicURL
|
|
25
|
+
* @param {string} localURL
|
|
26
|
+
*/
|
|
27
|
+
function printSuccess(publicURL, localURL) {
|
|
28
|
+
console.log();
|
|
29
|
+
console.log(' ββββββββββββββββββββββββββββββββββββββββββββββββββββ');
|
|
30
|
+
console.log(' β π nodetunnel β tunnel is live β');
|
|
31
|
+
console.log(' β βββββββββββββββββββββββββββββββββββββββββββββββββββ£');
|
|
32
|
+
console.log(` β π Public β ${publicURL.padEnd(32)}β`);
|
|
33
|
+
console.log(` β π» Local β ${localURL.padEnd(32)}β`);
|
|
34
|
+
console.log(` β βββββββββββββββββββββββββββββββββββββββββββββββββββ£`);
|
|
35
|
+
console.log(' β β‘ Forwarding requests... β');
|
|
36
|
+
console.log(' β π Press Ctrl+C to stop β');
|
|
37
|
+
console.log(' ββββββββββββββββββββββββββββββββββββββββββββββββββββ');
|
|
38
|
+
console.log();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Connect to the tunnel server and forward public HTTP traffic to localhost:<port>.
|
|
24
43
|
*
|
|
25
44
|
* @param {string} port local port (e.g. "8080")
|
|
26
45
|
* @param {{ host?: string, serverPort?: number }} [options] tunnel server (default localhost:9000)
|
|
@@ -29,10 +48,12 @@ import { newTunnel } from '../../internal/tunnel/tunnel.js';
|
|
|
29
48
|
async function startTunnel(port, options) {
|
|
30
49
|
const tunnel = await newTunnel(String(port), options);
|
|
31
50
|
|
|
32
|
-
|
|
51
|
+
const publicURL = tunnel.getPublicUrl();
|
|
52
|
+
const localURL = `http://localhost:${port}`;
|
|
53
|
+
printSuccess(publicURL, localURL);
|
|
33
54
|
|
|
34
55
|
return {
|
|
35
|
-
url:
|
|
56
|
+
url: publicURL,
|
|
36
57
|
stop: () => tunnel.stop(),
|
|
37
58
|
};
|
|
38
59
|
}
|