refactor: sysproxy集成

pull/180/head
xiaojunnuo 2020-11-28 21:13:37 +08:00
parent f830b0f457
commit a5add8f396
10 changed files with 21 additions and 14 deletions

View File

@ -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': {

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -38,8 +38,8 @@
<div>开启此项之后被代理应用关闭SSL校验也问题不大了</div>
</a-form-item>
<a-form-item label="根证书:" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-input addon-before="Cert" addon-after="" v-model="config.server.setting.rootCaFile.certPath" ></a-input>
<a-input addon-before="Key" addon-after="" v-model="config.server.setting.rootCaFile.keyPath" ></a-input>
<a-input addon-before="Cert" v-model="config.server.setting.rootCaFile.certPath" ></a-input>
<a-input addon-before="Key" v-model="config.server.setting.rootCaFile.keyPath" ></a-input>
</a-form-item>
<a-form-item label="启用脚本" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-tooltip title="关闭后github的clone加速链接复制也将关闭">
@ -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/')
}
}
}

View File

@ -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()

View File

@ -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) {

View File

@ -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