@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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpkrn/nodetunnel",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Expose a local HTTP server through a devtunnel/gotunnel-compatible server (yamux + JSON). Node.js 18+.",
5
5
  "keywords": [
6
6
  "tunnel",
@@ -20,7 +20,26 @@
20
20
  import { newTunnel } from '../../internal/tunnel/tunnel.js';
21
21
 
22
22
  /**
23
- * Connect to the tunnel server and forward public HTTP traffic to localhost:<port>.
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
- console.log('βœ…Public url:', tunnel.getPublicUrl());
51
+ const publicURL = tunnel.getPublicUrl();
52
+ const localURL = `http://localhost:${port}`;
53
+ printSuccess(publicURL, localURL);
33
54
 
34
55
  return {
35
- url: tunnel.getPublicUrl(),
56
+ url: publicURL,
36
57
  stop: () => tunnel.stop(),
37
58
  };
38
59
  }