perf: 支持关闭脚本插入
parent
98a2c845a3
commit
3ff608f6b4
|
@ -4,7 +4,10 @@ module.exports = {
|
|||
port: 1181,
|
||||
setting: {
|
||||
NODE_TLS_REJECT_UNAUTHORIZED: true,
|
||||
scriptDir: '../../../scripts/'
|
||||
script: {
|
||||
enabled: true,
|
||||
defaultDir: '../../../scripts/'
|
||||
}
|
||||
},
|
||||
intercepts: {
|
||||
'github.com': {
|
||||
|
|
|
@ -3,5 +3,5 @@ const server = require('@docmirror/mitmproxy')
|
|||
const config = JSON.parse(process.argv[2])
|
||||
const path = require('path')
|
||||
const scriptDir = '../../gui/extra/scripts/'
|
||||
config.setting.scriptDir = path.join(__dirname, scriptDir)
|
||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||
server.start(config)
|
||||
|
|
|
@ -7,6 +7,6 @@ let scriptDir = '../extra/scripts/'
|
|||
if (process.env.NODE_ENV === 'development') {
|
||||
scriptDir = '../extra/scripts/'
|
||||
}
|
||||
config.setting.scriptDir = path.join(__dirname, scriptDir)
|
||||
log.debug('scriptDir', config.setting.scriptDir)
|
||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||
log.debug('scriptDir', config.setting.script.defaultDir)
|
||||
server.start(config)
|
||||
|
|
|
@ -30,6 +30,7 @@ export default {
|
|||
this.status = this.$status
|
||||
return this.$api.config.reload().then(ret => {
|
||||
this.config = ret
|
||||
console.log('config', this.config)
|
||||
if (this.ready) {
|
||||
return this.ready(this.config)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
>
|
||||
<a-tab-pane tab="基本设置" key="1" >
|
||||
<a-form-item label="代理服务:" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox :checked="config.server.enabled" @change="config.server.enabled = $event">
|
||||
<a-checkbox v-model="config.server.enabled" >
|
||||
随应用启动
|
||||
</a-checkbox>
|
||||
<a-tag v-if="status.proxy.enabled" color="green">
|
||||
|
@ -32,11 +32,18 @@
|
|||
<a-input v-model="config.server.port"/>
|
||||
</a-form-item>
|
||||
<a-form-item label="校验SSL" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox :checked="config.server.setting.NODE_TLS_REJECT_UNAUTHORIZED" @change="config.server.setting.NODE_TLS_REJECT_UNAUTHORIZED = $event">
|
||||
<a-checkbox v-model="config.server.setting.NODE_TLS_REJECT_UNAUTHORIZED">
|
||||
NODE_TLS_REJECT_UNAUTHORIZED
|
||||
</a-checkbox>
|
||||
<div>开启此项之后,被代理应用关闭SSL校验也问题不大了</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="启用脚本" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-tooltip title="关闭后,github的clone加速链接复制也将关闭">
|
||||
<a-checkbox v-model="config.server.setting.script.enabled" >
|
||||
允许插入并运行脚本
|
||||
</a-checkbox>
|
||||
</a-tooltip>
|
||||
</a-form-item>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="拦截设置" key="2" >
|
||||
<vue-json-editor style="height:100%;" ref="editor" v-model="config.server.intercepts" mode="code" :show-btns="false" :expandedOnStart="true" @json-change="onJsonChange" ></vue-json-editor>
|
||||
|
|
|
@ -20,9 +20,9 @@ module.exports = {
|
|||
keys = [keys]
|
||||
}
|
||||
try {
|
||||
let tags = getScript('global', monkey.get(setting.scriptDir).global.script)
|
||||
let tags = getScript('global', monkey.get(setting.script.defaultDir).global.script)
|
||||
for (const key of keys) {
|
||||
const script = monkey.get(setting.scriptDir)[key]
|
||||
const script = monkey.get(setting.script.defaultDir)[key]
|
||||
if (script == null) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ module.exports = {
|
|||
const urlPath = rOptions.path
|
||||
const filename = urlPath.replace(contextPath, '')
|
||||
|
||||
const script = monkey.get(setting.scriptDir)[filename]
|
||||
const script = monkey.get(setting.script.defaultDir)[filename]
|
||||
|
||||
log.info('ds_script', filename, script != null)
|
||||
res.writeHead(200)
|
||||
|
|
|
@ -41,7 +41,9 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
|
|||
resolve()
|
||||
}
|
||||
try {
|
||||
reqIncpts.unshift(InsertScriptMiddleware)
|
||||
if (setting.script.enabled) {
|
||||
reqIncpts.unshift(InsertScriptMiddleware)
|
||||
}
|
||||
if (reqIncpts && reqIncpts.length > 0) {
|
||||
for (const reqIncpt of reqIncpts) {
|
||||
const goNext = reqIncpt.requestIntercept(context, req, res, ssl, next)
|
||||
|
@ -196,6 +198,10 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
|
|||
const next = () => {
|
||||
resolve()
|
||||
}
|
||||
if (!setting.script.enabled) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (resIncpts && resIncpts.length > 0) {
|
||||
let head = ''
|
||||
|
@ -209,6 +215,7 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
|
|||
body += append.body
|
||||
}
|
||||
}
|
||||
|
||||
InsertScriptMiddleware.responseInterceptor(req, res, proxyReq, proxyRes, ssl, next, { head, body })
|
||||
} else {
|
||||
next()
|
||||
|
|
Loading…
Reference in New Issue