@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.
- package/dist/cli.js +38 -31
- package/package.json +1 -1
- 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
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
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
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}
|