runlocal 0.5.1 → 0.7.0

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.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/lib.js +22 -13
  3. package/package.json +13 -4
package/index.js CHANGED
@@ -6,7 +6,7 @@ const { parseArgs, createConnection } = require("./lib");
6
6
  const BOLD = "\x1b[1m";
7
7
  const RESET = "\x1b[0m";
8
8
 
9
- const { port, host, apiKey } = parseArgs(process.argv.slice(2));
9
+ const { port, host, apiKey, subdomain } = parseArgs(process.argv.slice(2));
10
10
 
11
11
  console.log(`${BOLD}runlocal${RESET} — expose localhost:${port} to the internet`);
12
- createConnection({ host, port, apiKey, WebSocket });
12
+ createConnection({ host, port, apiKey, subdomain, WebSocket });
package/lib.js CHANGED
@@ -29,38 +29,45 @@ function parseArgs(argv) {
29
29
  let port = 3000;
30
30
  let host = process.env.RUNLOCAL_HOST || "wss://runlocal.eu";
31
31
  let apiKey = process.env.RUNLATER_API_KEY || readApiKeyFile();
32
+ let subdomain = null;
32
33
  for (let i = 0; i < argv.length; i++) {
33
- if (argv[i] === "--host" && argv[i + 1]) {
34
+ if ((argv[i] === "--server" || argv[i] === "--host") && argv[i + 1]) {
34
35
  host = argv[++i];
35
36
  } else if (argv[i] === "--api-key" && argv[i + 1]) {
36
37
  apiKey = argv[++i];
38
+ } else if (argv[i] === "--subdomain" && argv[i + 1]) {
39
+ subdomain = argv[++i];
37
40
  } else if (argv[i] === "--help" || argv[i] === "-h") {
38
41
  console.log("Usage: runlocal <port> [options]");
39
42
  console.log("");
40
- console.log(" Expose localhost to the internet via runlocal.eu");
43
+ console.log(" Expose localhost to the internet. Works with runlocal.eu");
44
+ console.log(" or any self-hosted runlocal server.");
41
45
  console.log("");
42
46
  console.log("Options:");
43
- console.log(" --host <url> Server URL (default: wss://runlocal.eu)");
47
+ console.log(" --server <url> Server URL (default: wss://runlocal.eu)");
44
48
  console.log(" --api-key <key> Runlater API key for stable subdomain");
49
+ console.log(" --subdomain <name> Request a specific subdomain");
45
50
  console.log(" --help, -h Show this help");
46
51
  console.log("");
47
- console.log("API key (checked in order):");
48
- console.log(" 1. --api-key flag");
49
- console.log(" 2. RUNLATER_API_KEY environment variable");
50
- console.log(" 3. ~/.runlater/api-key file");
52
+ console.log("Environment variables:");
53
+ console.log(" RUNLOCAL_HOST Server URL (same as --server)");
54
+ console.log(" RUNLATER_API_KEY API key (same as --api-key)");
51
55
  console.log("");
52
56
  console.log("Examples:");
53
- console.log(" npx runlocal 3000 Random subdomain");
54
- console.log(" npx runlocal 3000 --api-key pk_xxx Stable subdomain");
57
+ console.log(" npx runlocal 3000 Random subdomain");
58
+ console.log(" npx runlocal 3000 --api-key pk_xxx Stable subdomain");
59
+ console.log(" npx runlocal 3000 --subdomain my-api Custom subdomain");
60
+ console.log(" npx runlocal 3000 --server wss://tunnel.example.com Self-hosted");
55
61
  console.log("");
56
- console.log("A free runlater.eu account gives you a stable subdomain.");
62
+ console.log("Self-hosting: https://github.com/runlater-eu/runlocal");
63
+ console.log("Hosted version: https://runlocal.eu");
57
64
  process.exit(0);
58
65
  } else if (!argv[i].startsWith("-")) {
59
66
  port = parseInt(argv[i], 10);
60
67
  }
61
68
  }
62
69
 
63
- return { port, host, apiKey };
70
+ return { port, host, apiKey, subdomain };
64
71
  }
65
72
 
66
73
  function filterHeaders(headers) {
@@ -75,9 +82,10 @@ function filterHeaders(headers) {
75
82
  return filtered;
76
83
  }
77
84
 
78
- function buildWsUrl(host, apiKey) {
85
+ function buildWsUrl(host, apiKey, subdomain) {
79
86
  const params = new URLSearchParams({ vsn: "2.0.0" });
80
87
  if (apiKey) params.set("api_key", apiKey);
88
+ if (subdomain) params.set("subdomain", subdomain);
81
89
  return `${host}/tunnel/websocket?${params.toString()}`;
82
90
  }
83
91
 
@@ -170,13 +178,14 @@ function createConnection(options) {
170
178
  host,
171
179
  port,
172
180
  apiKey,
181
+ subdomain,
173
182
  WebSocket,
174
183
  onTunnelCreated,
175
184
  onClose,
176
185
  log = console.log,
177
186
  logError = console.error,
178
187
  } = options;
179
- const wsUrl = buildWsUrl(host, apiKey);
188
+ const wsUrl = buildWsUrl(host, apiKey, subdomain);
180
189
 
181
190
  let refCounter = 0;
182
191
  const nextRef = () => String(++refCounter);
package/package.json CHANGED
@@ -1,15 +1,24 @@
1
1
  {
2
2
  "name": "runlocal",
3
- "version": "0.5.1",
4
- "description": "Expose localhost to the internet via runlocal.eu",
3
+ "version": "0.7.0",
4
+ "description": "Expose localhost to the internet open source tunnel server",
5
5
  "bin": {
6
6
  "runlocal": "./index.js"
7
7
  },
8
- "files": ["index.js", "lib.js"],
8
+ "files": [
9
+ "index.js",
10
+ "lib.js"
11
+ ],
9
12
  "scripts": {
10
13
  "test": "node --test test/*.test.js"
11
14
  },
12
- "keywords": ["tunnel", "localhost", "ngrok", "dev", "https"],
15
+ "keywords": [
16
+ "tunnel",
17
+ "localhost",
18
+ "ngrok",
19
+ "dev",
20
+ "https"
21
+ ],
13
22
  "license": "MIT",
14
23
  "dependencies": {
15
24
  "ws": "^8.0.0"