@nora-link/client 1.0.5 → 1.0.6

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/dist/cli.js +38 -31
  2. package/package.json +1 -1
  3. package/src/cli.ts +37 -31
package/dist/cli.js CHANGED
@@ -18,40 +18,47 @@ commander_1.program
18
18
  }
19
19
  return previous;
20
20
  }, 'info')
21
- .requiredOption('-f, --forward <subdomain|label|url>', 'Tunnel subdomain to local url. Label is optional')
21
+ .requiredOption('-f, --forward <subdomain|label|url...>', 'Tunnel subdomain to local url. Label is optional')
22
22
  .requiredOption('-k, --key <api-key>', 'Api Key')
23
23
  .requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
24
24
  .addHelpText('afterAll', 'To tunnel a local port to the subdomain `test`, you can use `-f test|:3000`')
25
25
  .addHelpText('afterAll', 'To tunnel an ip to the subdomain `test`, you can use `-f test|192.168.1.130`')
26
26
  .parse();
27
27
  const options = commander_1.program.opts();
28
- const forward = Array.isArray(options.forward) ? options.forward : [options.forward];
29
- const tunnels = forward
30
- .filter((v) => typeof v === 'string')
31
- .map(v => {
32
- const [segment, labelOrUrl, urlPart] = v.split('|');
33
- let toUrl;
34
- const label = urlPart ? labelOrUrl : segment;
35
- const url = urlPart ?? labelOrUrl;
36
- if (/^https?:\/\//.test(url)) {
37
- toUrl = url;
38
- }
39
- else if (url.startsWith(':')) {
40
- //only port specified
41
- const port = +url.split(':')[1];
42
- toUrl = `http://127.0.0.1:${port}`;
43
- }
44
- else {
45
- toUrl = `http://${url}`;
46
- }
47
- return { remotePath: segment, localUrl: toUrl, label };
48
- });
49
- new client_1.Client({
50
- agent: `${name}@${version}`,
51
- hostname: options.host,
52
- secure: !options.nonSecure,
53
- tunnels,
54
- apiKey: options.key,
55
- logger: (0, logger_1.createConsoleLogger)(options.log),
56
- }).handle$
57
- .subscribe();
28
+ let tunnels = [];
29
+ if (Array.isArray(options.forward)) {
30
+ tunnels = options.forward
31
+ .filter((v) => typeof v === 'string')
32
+ .map(v => {
33
+ const [segment, labelOrUrl, urlPart] = v.split('|');
34
+ let toUrl;
35
+ const label = urlPart ? labelOrUrl : segment;
36
+ const url = urlPart ?? labelOrUrl;
37
+ if (/^https?:\/\//.test(url)) {
38
+ toUrl = url;
39
+ }
40
+ else if (url.startsWith(':')) {
41
+ //only port specified
42
+ const port = +url.split(':')[1];
43
+ toUrl = `http://127.0.0.1:${port}`;
44
+ }
45
+ else {
46
+ toUrl = `http://${url}`;
47
+ }
48
+ return { remotePath: segment, localUrl: toUrl, label };
49
+ });
50
+ }
51
+ if (!tunnels.length) {
52
+ console.info('no valid tunnels specified');
53
+ process.exit(1);
54
+ }
55
+ else {
56
+ new client_1.Client({
57
+ agent: `${name}@${version}`,
58
+ hostname: options.host,
59
+ secure: !options.nonSecure,
60
+ tunnels,
61
+ apiKey: options.key,
62
+ logger: (0, logger_1.createConsoleLogger)(options.log),
63
+ }).handle$.subscribe();
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nora-link/client",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"
package/src/cli.ts CHANGED
@@ -19,7 +19,7 @@ program
19
19
  }
20
20
  return previous;
21
21
  }, 'info')
22
- .requiredOption('-f, --forward <subdomain|label|url>', 'Tunnel subdomain to local url. Label is optional')
22
+ .requiredOption('-f, --forward <subdomain|label|url...>', 'Tunnel subdomain to local url. Label is optional')
23
23
  .requiredOption('-k, --key <api-key>', 'Api Key')
24
24
  .requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
25
25
  .addHelpText('afterAll', 'To tunnel a local port to the subdomain `test`, you can use `-f test|:3000`')
@@ -28,36 +28,42 @@ program
28
28
 
29
29
  const options = program.opts();
30
30
 
31
- const forward = Array.isArray(options.forward) ? options.forward : [options.forward];
32
- const tunnels: ClientConnectionOptions['tunnels'] = forward
33
- .filter((v): v is string => typeof v === 'string')
34
- .map(v => {
35
- const [segment, labelOrUrl, urlPart] = v.split('|');
36
- let toUrl: string;
37
-
38
- const label = urlPart ? labelOrUrl : segment;
39
- const url = urlPart ?? labelOrUrl;
40
-
41
- if (/^https?:\/\//.test(url)) {
42
- toUrl = url;
43
- } else if (url.startsWith(':')) {
44
- //only port specified
45
- const port = +url.split(':')[1];
46
- toUrl = `http://127.0.0.1:${port}`;
47
- } else {
48
- toUrl = `http://${url}`;
49
- }
31
+ let tunnels: ClientConnectionOptions['tunnels'] = [];
32
+ if (Array.isArray(options.forward)) {
33
+ tunnels = options.forward
34
+ .filter((v): v is string => typeof v === 'string')
35
+ .map(v => {
36
+ const [segment, labelOrUrl, urlPart] = v.split('|');
37
+ let toUrl: string;
38
+
39
+ const label = urlPart ? labelOrUrl : segment;
40
+ const url = urlPart ?? labelOrUrl;
50
41
 
51
- return { remotePath: segment, localUrl: toUrl, label };
52
- });
42
+ if (/^https?:\/\//.test(url)) {
43
+ toUrl = url;
44
+ } else if (url.startsWith(':')) {
45
+ //only port specified
46
+ const port = +url.split(':')[1];
47
+ toUrl = `http://127.0.0.1:${port}`;
48
+ } else {
49
+ toUrl = `http://${url}`;
50
+ }
53
51
 
54
- new Client({
55
- agent: `${name}@${version}`,
56
- hostname: options.host,
57
- secure: !options.nonSecure,
58
- tunnels,
59
- apiKey: options.key,
60
- logger: createConsoleLogger(options.log),
61
- }).handle$
62
- .subscribe();
52
+ return { remotePath: segment, localUrl: toUrl, label };
53
+ });
54
+ }
63
55
 
56
+ if (!tunnels.length) {
57
+ console.info('no valid tunnels specified');
58
+ process.exit(1);
59
+ }
60
+ else {
61
+ new Client({
62
+ agent: `${name}@${version}`,
63
+ hostname: options.host,
64
+ secure: !options.nonSecure,
65
+ tunnels,
66
+ apiKey: options.key,
67
+ logger: createConsoleLogger(options.log),
68
+ }).handle$.subscribe();
69
+ }