From a5add8f396d128b019630906bdd329e81b0d8397 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 28 Nov 2020 21:13:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20sysproxy=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config/index.js | 6 +++--- packages/core/src/shell/scripts/set-system-proxy/index.js | 3 ++- packages/core/src/utils/util.log.js | 3 ++- packages/gui/src/bridge/index.js | 1 + packages/gui/src/bridge/mitmproxy.js | 3 +-- packages/gui/src/utils/util.log.js | 3 ++- packages/gui/src/view/pages/server.vue | 6 +++--- packages/mitmproxy/src/lib/choice/index.js | 2 +- packages/mitmproxy/src/lib/interceptor/impl/proxy.js | 5 ++++- packages/mitmproxy/src/utils/util.log.js | 3 ++- 10 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index ad5aab56..da7cecfe 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -49,11 +49,11 @@ module.exports = { desc: 'clone加速复制链接脚本' }, '/.*': { - proxy: 'github.com', + proxy: 'gh.docmirror.top/_proxy', backup: [ - 'gh.docmirror.top/_proxy' + 'github.com' ], - desc: '如果出现dev-sidecar报错,可能是备用加速地址dns被污染了,需要将本条配置删除' + desc: '如果出现dev-sidecar报错,可能是加速地址dns被污染了,需要将本条配置删除' } }, 'api.github.com': { diff --git a/packages/core/src/shell/scripts/set-system-proxy/index.js b/packages/core/src/shell/scripts/set-system-proxy/index.js index 37b8472a..842c797f 100644 --- a/packages/core/src/shell/scripts/set-system-proxy/index.js +++ b/packages/core/src/shell/scripts/set-system-proxy/index.js @@ -36,7 +36,7 @@ const _lanIP = [ async function _winUnsetProxy (exec) { // eslint-disable-next-line no-constant-condition if (true) { - const proxyPath = path.resolve(__dirname, './extra/sysproxy.exe') + const proxyPath = getProxyExePath() await execFile(proxyPath, ['off']) return } @@ -57,6 +57,7 @@ async function _winUnsetProxy (exec) { function getProxyExePath () { const proxyPath = process.env.DS_SYSPROXY_PATH + log.info('proxyPath', proxyPath) if (proxyPath) { return proxyPath } diff --git a/packages/core/src/utils/util.log.js b/packages/core/src/utils/util.log.js index 04c8a5ae..ca6d0222 100644 --- a/packages/core/src/utils/util.log.js +++ b/packages/core/src/utils/util.log.js @@ -3,9 +3,10 @@ const config = require('../config/index') function getDefaultConfigBasePath () { return config.server.setting.userBasePath } +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/core.log' } }, - categories: { default: { appenders: ['file', 'std'], level: 'info' } } + categories: { default: { appenders: ['file', 'std'], level: level } } }) const logger = log4js.getLogger('server') module.exports = logger diff --git a/packages/gui/src/bridge/index.js b/packages/gui/src/bridge/index.js index caa6fd4d..f539e331 100644 --- a/packages/gui/src/bridge/index.js +++ b/packages/gui/src/bridge/index.js @@ -6,6 +6,7 @@ import JSON5 from 'json5' import path from 'path' const pk = require('../../package.json') const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') +process.env.DS_SYSPROXY_PATH = path.join(__dirname, '../extra/sysproxy.exe') const log = require('../utils/util.log') const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath diff --git a/packages/gui/src/bridge/mitmproxy.js b/packages/gui/src/bridge/mitmproxy.js index acd487ac..9cef1d7b 100644 --- a/packages/gui/src/bridge/mitmproxy.js +++ b/packages/gui/src/bridge/mitmproxy.js @@ -1,15 +1,14 @@ // eslint-disable-next-line no-unused-vars const server = require('@docmirror/mitmproxy') const configPath = process.argv[2] - const fs = require('fs') const path = require('path') const configJson = fs.readFileSync(configPath) const config = JSON.parse(configJson) - let scriptDir = '../extra/scripts/' if (process.env.NODE_ENV === 'development') { scriptDir = '../extra/scripts/' } config.setting.script.defaultDir = path.join(__dirname, scriptDir) + server.start(config) diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js index 8507a401..3f5fd189 100644 --- a/packages/gui/src/utils/util.log.js +++ b/packages/gui/src/utils/util.log.js @@ -3,9 +3,10 @@ const DevSidecar = require('@docmirror/dev-sidecar') const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath } +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/gui.log' } }, - categories: { default: { appenders: ['file', 'std'], level: 'info' } } + categories: { default: { appenders: ['file', 'std'], level: level } } }) const logger = log4js.getLogger('server') module.exports = logger diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue index e3128c47..bf8233b2 100644 --- a/packages/gui/src/view/pages/server.vue +++ b/packages/gui/src/view/pages/server.vue @@ -38,8 +38,8 @@
开启此项之后,被代理应用关闭SSL校验也问题不大了
- - + + @@ -148,7 +148,7 @@ export default { }, async openLog () { const dir = await this.$api.info.getConfigDir() - this.$api.ipc.openPath(dir + '/logs/server.log') + this.$api.ipc.openPath(dir + '/logs/') } } } diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js index e7b8a6e2..69a42a89 100644 --- a/packages/mitmproxy/src/lib/choice/index.js +++ b/packages/mitmproxy/src/lib/choice/index.js @@ -39,7 +39,7 @@ class DynamicChoice { if (this.count[item]) { continue } - this.count[item] = { value: item, total: defaultTotal, error: 0, keepErrorCount: 0, successRate: 1 } + this.count[item] = { value: item, total: defaultTotal, error: 0, keepErrorCount: 0, successRate: 0.5 } defaultTotal-- } this.value = backupList.shift() diff --git a/packages/mitmproxy/src/lib/interceptor/impl/proxy.js b/packages/mitmproxy/src/lib/interceptor/impl/proxy.js index d9a70bbb..3176535c 100644 --- a/packages/mitmproxy/src/lib/interceptor/impl/proxy.js +++ b/packages/mitmproxy/src/lib/interceptor/impl/proxy.js @@ -49,7 +49,10 @@ module.exports = { rOptions.port = rOptions.protocol === 'https:' ? 443 : 80 } log.info('proxy:', rOptions.hostname, proxyTarget) - log.debug('proxy choice:', JSON.stringify(context.requestCount)) + if (context.requestCount) { + log.debug('proxy choice:', JSON.stringify(context.requestCount)) + } + return true }, is (interceptOpt) { diff --git a/packages/mitmproxy/src/utils/util.log.js b/packages/mitmproxy/src/utils/util.log.js index b7e78e86..7101b7e4 100644 --- a/packages/mitmproxy/src/utils/util.log.js +++ b/packages/mitmproxy/src/utils/util.log.js @@ -1,8 +1,9 @@ const log4js = require('log4js') const proxyConfig = require('../lib/proxy/common/config') +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' log4js.configure({ appenders: { std: { type: 'stdout', level: 'debug' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: proxyConfig.getDefaultCABasePath() + '/logs/server.log' } }, - categories: { default: { appenders: ['file', 'std'], level: 'info' } } + categories: { default: { appenders: ['file', 'std'], level: level } } }) const logger = log4js.getLogger('server') module.exports = logger