@appthen/cli 1.1.24 → 1.1.26
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/bin/main.js +57 -0
- package/dist/index.js +25 -7
- package/package.json +8 -2
package/bin/main.js
CHANGED
|
@@ -358,5 +358,62 @@ program
|
|
|
358
358
|
}
|
|
359
359
|
});
|
|
360
360
|
|
|
361
|
+
/**
|
|
362
|
+
* proxy命令
|
|
363
|
+
* 启动本地代理服务器,解决跨域和私有域接口访问问题
|
|
364
|
+
* 必需参数:
|
|
365
|
+
* --target: 目标地址
|
|
366
|
+
* --port: 监听端口
|
|
367
|
+
* 可选参数:
|
|
368
|
+
* --daemon: 以守护进程方式运行
|
|
369
|
+
* --debug: 调试模式
|
|
370
|
+
* stop: 停止代理服务
|
|
371
|
+
*/
|
|
372
|
+
program
|
|
373
|
+
.command('proxy')
|
|
374
|
+
.description('start local proxy server to solve CORS and private network access')
|
|
375
|
+
.requiredOption('--target <target>', 'target server address, e.g. http://localhost:3000')
|
|
376
|
+
.requiredOption('--port <port>', 'local listen port, e.g. 9000')
|
|
377
|
+
.option('--daemon', 'run as daemon process', false)
|
|
378
|
+
.option('--debug', 'debug mode, process will not exit automatically', false)
|
|
379
|
+
.option('--stop', 'stop proxy server', false)
|
|
380
|
+
.on('--help', function () {
|
|
381
|
+
console.log('\n用法示例:');
|
|
382
|
+
console.log(' # 启动本地代理,将9000端口转发到目标服务');
|
|
383
|
+
console.log(' $ yourcli proxy --target http://192.168.1.100:8080 --port 9000');
|
|
384
|
+
console.log('\n # 以守护进程方式运行');
|
|
385
|
+
console.log(' $ yourcli proxy --target http://192.168.1.100:8080 --port 9000 --daemon');
|
|
386
|
+
console.log('\n # 停止代理服务');
|
|
387
|
+
console.log(' $ yourcli proxy --stop');
|
|
388
|
+
console.log('\n参数说明:');
|
|
389
|
+
console.log(' --target 目标服务地址(必填),如 http://localhost:3000');
|
|
390
|
+
console.log(' --port 本地监听端口(必填),如 9000');
|
|
391
|
+
console.log(' --daemon 以守护进程方式运行(可选)');
|
|
392
|
+
console.log(' --debug 调试模式,进程不会自动退出(可选)');
|
|
393
|
+
console.log(' --stop 停止代理服务(可选)');
|
|
394
|
+
})
|
|
395
|
+
.action(async function doProxy(command) {
|
|
396
|
+
const options = command.opts();
|
|
397
|
+
if (options.stop) {
|
|
398
|
+
// 停止代理
|
|
399
|
+
const stopped = require('../dist/index.js').stopProxy();
|
|
400
|
+
if (stopped) {
|
|
401
|
+
console.log('代理服务已停止');
|
|
402
|
+
process.exit(0);
|
|
403
|
+
} else {
|
|
404
|
+
console.log('没有找到运行中的代理服务');
|
|
405
|
+
process.exit(1);
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
// 启动代理
|
|
410
|
+
await require('../dist/index.js').startProxy({
|
|
411
|
+
target: options.target,
|
|
412
|
+
port: options.port,
|
|
413
|
+
daemon: options.daemon,
|
|
414
|
+
debug: options.debug,
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
361
418
|
// 解析命令行参数
|
|
362
419
|
program.parse(process.argv);
|