@cliz/inlets
Version:
Cloud Native Tunnel
71 lines (70 loc) • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const cli_1 = require("@cliz/cli");
const config_1 = require("../config");
const client_1 = require("../core/client");
exports.default = (0, cli_1.defineSubCommand)(createCommand => {
return createCommand('inlets client')
.argument('type', 'Network type, support: http | tcp', {
validator: /^(tcp|http)$/,
})
.argument('upstream', 'Upstream server, such as 127.0.0.1:9000, allow port only 9000', {
validator: /^(\d+|.+:\d+)$/,
})
.option('-p, --port <port>', 'Custom tunnel port for tcp')
.option('-s, --sub-domain <subDomain>', 'Custom tunnel sub domain for http')
.option('-t, --token <token>', 'Authentication token', {})
.option('--credentials <credentials>', 'Authentication credientials', {
default: process.env.CREDENTIALS,
})
.option('-r, --remote <remote>', 'Server address, default "inlets.zcorky.com:443"', {
default: config_1.default.defaultRemote,
})
.option('--remote-tcp-port <remoteTCPPort>', 'Server tcp port, default 8443', {
default: config_1.default.defaultTCPPort,
})
.option('--healthcheck-interval <healthcheckInterval>', 'Service health check interval, default: 30s', {
default: config_1.default.defaultHealthCheckInterval,
})
.option('--report-url <reportUrl>', 'Error report url, support dingtalk, feishu, wecom, slack', {
default: process.env.REPORT_URL,
})
.action(({ args, options, program, logger }) => {
let authType = 'public';
const type = args.type;
if (type !== 'http') {
if (!options.token && !options.credentials) {
throw new Error(`token or credentials is required`);
}
}
let clientId, clientSecret;
if (options.credentials) {
[clientId, clientSecret] = options.credentials.split(':');
authType = 'credentials';
}
else if (options.token) {
authType = 'token';
}
const _options = {
...options,
type,
upstream: args.upstream,
authType,
token: options.token,
clientId,
clientSecret,
version: program.getVersion(),
remoteTCPPort: options.remoteTcpPort,
onError: (error) => {
if (error) {
logger.error('cli error:', error);
process.exit(1);
}
},
};
if (String(process.env.LOG_LEVEL).toLowerCase() === 'debug') {
logger.info('running config:', _options);
}
return (0, client_1.client)(_options);
});
});