From 447241f3932f161a78c965a86a8f9140c5543ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Sat, 30 Nov 2024 21:57:24 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20`api`=20=E5=B8=B8=E9=87=8F=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8F=90=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/index.js | 84 ++++++++++++++++----------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/packages/mitmproxy/src/index.js b/packages/mitmproxy/src/index.js index 4e0dba63..e46bd798 100644 --- a/packages/mitmproxy/src/index.js +++ b/packages/mitmproxy/src/index.js @@ -7,48 +7,6 @@ const { fireError, fireStatus } = require('./utils/util.process') let servers = [] -function registerProcessListener () { - process.on('message', (msg) => { - log.info('child get msg:', JSON.stringify(msg)) - if (msg.type === 'action') { - api[msg.event.key](msg.event.params) - } else if (msg.type === 'speed') { - speedTest.action(msg.event) - } - }) - - process.on('SIGINT', () => { - log.info('on sigint : closed ') - process.exit(0) - }) - - // 避免异常崩溃 - process.on('uncaughtException', (err) => { - if (err.code === 'ECONNABORTED') { - // log.error(err.errno) - return - } - log.error('Process uncaughtException:', err) - }) - - process.on('unhandledRejection', (err, p) => { - log.info('Process unhandledRejection at: Promise', p, 'err:', err) - // application specific logging, throwing an error, or other logic here - }) - process.on('uncaughtExceptionMonitor', (err, origin) => { - log.info('Process uncaughtExceptionMonitor:', err, origin) - }) - process.on('exit', (code, signal) => { - log.info('代理服务进程被关闭:', code, signal) - }) - process.on('beforeExit', (code, signal) => { - console.log('Process beforeExit event with code: ', code, signal) - }) - process.on('SIGPIPE', (code, signal) => { - log.warn('sub Process SIGPIPE', code, signal) - }) -} - const api = { async start (config) { const proxyOptions = ProxyOptions(config) @@ -119,6 +77,48 @@ const api = { }, } +function registerProcessListener () { + process.on('message', (msg) => { + log.info('child get msg:', JSON.stringify(msg)) + if (msg.type === 'action') { + api[msg.event.key](msg.event.params) + } else if (msg.type === 'speed') { + speedTest.action(msg.event) + } + }) + + process.on('SIGINT', () => { + log.info('on sigint : closed ') + process.exit(0) + }) + + // 避免异常崩溃 + process.on('uncaughtException', (err) => { + if (err.code === 'ECONNABORTED') { + // log.error(err.errno) + return + } + log.error('Process uncaughtException:', err) + }) + + process.on('unhandledRejection', (err, p) => { + log.info('Process unhandledRejection at: Promise', p, 'err:', err) + // application specific logging, throwing an error, or other logic here + }) + process.on('uncaughtExceptionMonitor', (err, origin) => { + log.info('Process uncaughtExceptionMonitor:', err, origin) + }) + process.on('exit', (code, signal) => { + log.info('代理服务进程被关闭:', code, signal) + }) + process.on('beforeExit', (code, signal) => { + console.log('Process beforeExit event with code: ', code, signal) + }) + process.on('SIGPIPE', (code, signal) => { + log.warn('sub Process SIGPIPE', code, signal) + }) +} + module.exports = { ...api, config: proxyConfig,