Merge remote-tracking branch 'origin/master'
commit
91f44b77f5
17
README.md
17
README.md
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
### 5、 npm加速
|
### 5、 npm加速
|
||||||
* 支持开启npm代理
|
* 支持开启npm代理
|
||||||
* 切换npm淘宝registry
|
* 官方与淘宝npm registry一键切换,
|
||||||
* 某些npm install的时候,并且使用cnpm也无法安装时,可以尝试开启npm代理再试
|
* 某些npm install的时候,并且使用cnpm也无法安装时,可以尝试开启npm代理再试
|
||||||
|
|
||||||
### 6、 更多加速配置
|
### 6、 更多加速配置
|
||||||
|
@ -44,12 +44,14 @@
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
目前仅支持windows
|
目前仅支持windows
|
||||||
|
|
||||||
### DevSidecar桌面应用
|
### DevSidecar桌面应用
|
||||||
|
|
||||||
#### 1 下载安装包
|
#### 1 下载安装包
|
||||||
|
下载安装包:
|
||||||
|
|
||||||
|
[阿里云](https://dev-sidecar.docmirror.cn/update/DevSidecar-1.2.1.exe)
|
||||||
|
|
||||||
下载安装包:
|
|
||||||
[阿里云](https://dev-sidecar.docmirror.cn/update/DevSidecar-1.2.0.exe)
|
|
||||||
[Gitee Release](https://gitee.com/docmirror/dev-sidecar/releases)
|
[Gitee Release](https://gitee.com/docmirror/dev-sidecar/releases)
|
||||||
[Github Release](https://github.com/docmirror/dev-sidecar/releases)
|
[Github Release](https://github.com/docmirror/dev-sidecar/releases)
|
||||||
|
|
||||||
|
@ -88,17 +90,12 @@
|
||||||
建议遇到打开比较慢的国外网站,可以优先尝试将该域名添加到dns设置中(注意:被GFW封杀的无效)
|
建议遇到打开比较慢的国外网站,可以优先尝试将该域名添加到dns设置中(注意:被GFW封杀的无效)
|
||||||
如果还访问不了,就需要寻找镜像cdn进行拦截代理
|
如果还访问不了,就需要寻找镜像cdn进行拦截代理
|
||||||
|
|
||||||
### npm加速
|
|
||||||
1. yarn 设置淘宝镜像registry
|
|
||||||
2. npm设置官方registry。
|
|
||||||
3. 项目install使用yarn,发布包publish用npm,互不影响
|
|
||||||
4. 某些库用cnpm也下载不下来的话,可以试试打开dev-sidecar的npm加速
|
|
||||||
|
|
||||||
### 其他加速
|
### 其他加速
|
||||||
1. git clone 加速
|
1. git clone 加速
|
||||||
|
|
||||||
方式1:快捷复制:
|
方式1:快捷复制:
|
||||||
开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
|
> 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
|
||||||
|
|
||||||
方式2:
|
方式2:
|
||||||
> 使用方式用实际的名称替换{}的内容,即可加速clone
|
> 使用方式用实际的名称替换{}的内容,即可加速clone
|
||||||
> https://hub.fastgit.org/{username}/{reponame}.git
|
> https://hub.fastgit.org/{username}/{reponame}.git
|
||||||
|
|
|
@ -14,5 +14,5 @@
|
||||||
"ignore": []
|
"ignore": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1.2.0"
|
"version": "1.2.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@docmirror/dev-sidecar",
|
"name": "@docmirror/dev-sidecar",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@docmirror/dev-sidecar",
|
"name": "@docmirror/dev-sidecar",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"description": "给开发者的加速代理工具",
|
"description": "给开发者的加速代理工具",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
"start": "node ./start"
|
"start": "node ./start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docmirror/mitmproxy": "^1.2.0",
|
"@docmirror/mitmproxy": "^1.2.1",
|
||||||
"agentkeepalive": "^2.1.1",
|
"agentkeepalive": "^2.1.1",
|
||||||
"charset": "^1.0.0",
|
"charset": "^1.0.0",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const Shell = require('./shell')
|
const Shell = require('./shell')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const defConfig = require('./config/index.js')
|
const defConfig = require('./config/index.js')
|
||||||
const proxyServer = require('@docmirror/mitmproxy')
|
|
||||||
let configTarget = lodash.cloneDeep(defConfig)
|
let configTarget = lodash.cloneDeep(defConfig)
|
||||||
function _deleteDisabledItem (target) {
|
function _deleteDisabledItem (target) {
|
||||||
lodash.forEach(target, (item, key) => {
|
lodash.forEach(target, (item, key) => {
|
||||||
|
@ -13,6 +13,7 @@ function _deleteDisabledItem (target) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const configApi = {
|
const configApi = {
|
||||||
get () {
|
get () {
|
||||||
return configTarget
|
return configTarget
|
||||||
|
@ -68,7 +69,7 @@ const configApi = {
|
||||||
})
|
})
|
||||||
if (list.length > 0) {
|
if (list.length > 0) {
|
||||||
const context = {
|
const context = {
|
||||||
ca_cert_path: proxyServer.config.getDefaultCACertPath()
|
root_ca_cert_path: configApi.get().server.setting.rootCaFile.certPath
|
||||||
}
|
}
|
||||||
for (const item of noSetList) {
|
for (const item of noSetList) {
|
||||||
if (item.value.indexOf('${') >= 0) {
|
if (item.value.indexOf('${') >= 0) {
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
|
const path = require('path')
|
||||||
|
function getUserBasePath () {
|
||||||
|
const userHome = process.env.USERPROFILE
|
||||||
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
|
}
|
||||||
|
function getRootCaCertPath () {
|
||||||
|
return getUserBasePath() + '/dev-sidecar.ca.crt'
|
||||||
|
}
|
||||||
|
function getRootCaKeyPath () {
|
||||||
|
return getUserBasePath() + '/dev-sidecar.ca.key.pem'
|
||||||
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
server: {
|
server: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -7,6 +18,11 @@ module.exports = {
|
||||||
script: {
|
script: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
defaultDir: '../../../scripts/'
|
defaultDir: '../../../scripts/'
|
||||||
|
},
|
||||||
|
userBasePath: getUserBasePath(),
|
||||||
|
rootCaFile: {
|
||||||
|
certPath: getRootCaCertPath(),
|
||||||
|
keyPath: getRootCaKeyPath()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
intercepts: {
|
intercepts: {
|
||||||
|
|
|
@ -4,15 +4,12 @@ const event = require('./event')
|
||||||
const shell = require('./shell')
|
const shell = require('./shell')
|
||||||
const modules = require('./modules')
|
const modules = require('./modules')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const proxyServer = require('@docmirror/mitmproxy')
|
|
||||||
const proxyConfig = proxyServer.config
|
|
||||||
const log = require('./utils/util.log')
|
const log = require('./utils/util.log')
|
||||||
const context = {
|
const context = {
|
||||||
config,
|
config,
|
||||||
shell,
|
shell,
|
||||||
status,
|
status,
|
||||||
event,
|
event,
|
||||||
rootCaFile: proxyConfig.getDefaultCACertPath(),
|
|
||||||
log
|
log
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +124,7 @@ module.exports = {
|
||||||
shell,
|
shell,
|
||||||
server,
|
server,
|
||||||
proxy,
|
proxy,
|
||||||
plugin
|
plugin,
|
||||||
|
log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const nodeConfig = require('./config')
|
const nodeConfig = require('./config')
|
||||||
const NodePlugin = function (context) {
|
const NodePlugin = function (context) {
|
||||||
const { config, shell, event, rootCaFile, log } = context
|
const { config, shell, event, log } = context
|
||||||
const nodeApi = {
|
const nodeApi = {
|
||||||
async start () {
|
async start () {
|
||||||
try {
|
try {
|
||||||
|
@ -101,16 +101,17 @@ const NodePlugin = function (context) {
|
||||||
NODE_TLS_REJECT_UNAUTHORIZED: false
|
NODE_TLS_REJECT_UNAUTHORIZED: false
|
||||||
*/
|
*/
|
||||||
const nodeConfig = config.get().plugin.node
|
const nodeConfig = config.get().plugin.node
|
||||||
|
const rootCaCertFile = config.get().server.setting.rootCaFile.certPath
|
||||||
if (nodeConfig.setting['strict-ssl']) {
|
if (nodeConfig.setting['strict-ssl']) {
|
||||||
cmds.push('npm config set strict-ssl false')
|
cmds.push('npm config set strict-ssl false')
|
||||||
}
|
}
|
||||||
if (nodeConfig.setting.cafile) {
|
if (nodeConfig.setting.cafile) {
|
||||||
cmds.push(`npm config set cafile "${rootCaFile}"`)
|
cmds.push(`npm config set cafile "${rootCaCertFile}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeConfig.setting.NODE_EXTRA_CA_CERTS) {
|
if (nodeConfig.setting.NODE_EXTRA_CA_CERTS) {
|
||||||
cmds.push(`npm config set NODE_EXTRA_CA_CERTS "${rootCaFile}"`)
|
cmds.push(`npm config set NODE_EXTRA_CA_CERTS "${rootCaCertFile}"`)
|
||||||
env.push({ key: 'NODE_EXTRA_CA_CERTS', value: rootCaFile })
|
env.push({ key: 'NODE_EXTRA_CA_CERTS', value: rootCaCertFile })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeConfig.setting.NODE_TLS_REJECT_UNAUTHORIZED) {
|
if (nodeConfig.setting.NODE_TLS_REJECT_UNAUTHORIZED) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ const ProxyPlugin = function (context) {
|
||||||
async unsetProxy () {
|
async unsetProxy () {
|
||||||
try {
|
try {
|
||||||
await shell.setSystemProxy()
|
await shell.setSystemProxy()
|
||||||
event.fire('status', { key: 'proxy.enabled', vlaue: false })
|
event.fire('status', { key: 'proxy.enabled', value: false })
|
||||||
log.info('关闭系统代理成功')
|
log.info('关闭系统代理成功')
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ const status = require('../../status')
|
||||||
const lodash = require('lodash')
|
const lodash = require('lodash')
|
||||||
const fork = require('child_process').fork
|
const fork = require('child_process').fork
|
||||||
const log = require('../../utils/util.log')
|
const log = require('../../utils/util.log')
|
||||||
|
const fs = require('fs')
|
||||||
let server
|
let server
|
||||||
function fireStatus (status) {
|
function fireStatus (status) {
|
||||||
event.fire('status', { key: 'server.enabled', value: status })
|
event.fire('status', { key: 'server.enabled', value: status })
|
||||||
|
@ -45,7 +46,10 @@ const serverApi = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// fireStatus('ing') // 启动中
|
// fireStatus('ing') // 启动中
|
||||||
const serverProcess = fork(mitmproxyPath, [JSON.stringify(serverConfig)])
|
const basePath = serverConfig.setting.userBasePath
|
||||||
|
const runningConfig = basePath + '/running.json'
|
||||||
|
fs.writeFileSync(runningConfig, JSON.stringify(serverConfig))
|
||||||
|
const serverProcess = fork(mitmproxyPath, [runningConfig])
|
||||||
server = {
|
server = {
|
||||||
id: serverProcess.pid,
|
id: serverProcess.pid,
|
||||||
process: serverProcess,
|
process: serverProcess,
|
||||||
|
@ -64,7 +68,7 @@ const serverApi = {
|
||||||
event.fire('error', { key: 'server', value: 'EADDRINUSE', error: msg.event })
|
event.fire('error', { key: 'server', value: 'EADDRINUSE', error: msg.event })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { port: config.port }
|
return { port: runningConfig.port }
|
||||||
},
|
},
|
||||||
async kill () {
|
async kill () {
|
||||||
if (server) {
|
if (server) {
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
const Shell = require('../shell')
|
const Shell = require('../shell')
|
||||||
const execute = Shell.execute
|
const execute = Shell.execute
|
||||||
const proxyServer = require('@docmirror/mitmproxy')
|
|
||||||
const executor = {
|
const executor = {
|
||||||
async windows (exec) {
|
async windows (exec, { certPath }) {
|
||||||
const cmds = ['start ' + proxyServer.config.getDefaultCACertPath()]
|
const cmds = ['start "" "' + certPath + '"']
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const ret = await exec(cmds, { type: 'cmd' })
|
const ret = await exec(cmds, { type: 'cmd' })
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
async linux (exec, { port }) {
|
async linux (exec, { certPath }) {
|
||||||
throw Error('暂未实现此功能')
|
throw Error('暂未实现此功能')
|
||||||
},
|
},
|
||||||
async mac (exec, { port }) {
|
async mac (exec, { certPath }) {
|
||||||
throw Error('暂未实现此功能')
|
throw Error('暂未实现此功能')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
const log4js = require('log4js')
|
const log4js = require('log4js')
|
||||||
const path = require('path')
|
const config = require('../config/index')
|
||||||
const getDefaultConfigBasePath = function () {
|
function getDefaultConfigBasePath () {
|
||||||
const userHome = process.env.HOME || process.env.USERPROFILE
|
return config.server.setting.userBasePath
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
|
||||||
}
|
}
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/core.log' } },
|
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/core.log' } },
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
const proxyConfig = require('@docmirror/mitmproxy/config.js')
|
||||||
|
module.exports = {
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const server = require('@docmirror/mitmproxy')
|
const server = require('@docmirror/mitmproxy')
|
||||||
const config = JSON.parse(process.argv[2])
|
const configPath = process.argv[2]
|
||||||
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const configJson = fs.readFileSync(configPath)
|
||||||
|
const config = JSON.parse(configJson)
|
||||||
const scriptDir = '../../gui/extra/scripts/'
|
const scriptDir = '../../gui/extra/scripts/'
|
||||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||||
server.start(config)
|
server.start(config)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
abort: true
|
abort: true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
plugin: {
|
plugin: {
|
||||||
node: {
|
node: {
|
||||||
|
|
|
@ -93,15 +93,16 @@
|
||||||
lodash "^4.17.19"
|
lodash "^4.17.19"
|
||||||
to-fast-properties "^2.0.0"
|
to-fast-properties "^2.0.0"
|
||||||
|
|
||||||
"@docmirror/mitmproxy@^1.1.0":
|
"@docmirror/mitmproxy@^1.2.0":
|
||||||
version "1.1.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.1.0.tgz#d2dfa4c8047306c40105e0673365fdb4182be39b"
|
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e"
|
||||||
integrity sha512-KgNQ24o18G3Gnw9F9EkKKIKuEf3EnHh2uASMs72HvmuLobZo+D+0L+lL2xYPp+w5t8aXt0bgQeK8lRcz2C6wWw==
|
integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg==
|
||||||
dependencies:
|
dependencies:
|
||||||
agentkeepalive "^2.1.1"
|
agentkeepalive "^2.1.1"
|
||||||
child_process "^1.0.2"
|
child_process "^1.0.2"
|
||||||
colors "^1.1.2"
|
colors "^1.1.2"
|
||||||
commander "^2.9.0"
|
commander "^2.9.0"
|
||||||
|
crypto-js "^4.0.0"
|
||||||
debug "^4.1.1"
|
debug "^4.1.1"
|
||||||
dns-over-http "^0.2.0"
|
dns-over-http "^0.2.0"
|
||||||
dns-over-tls "^0.0.8"
|
dns-over-tls "^0.0.8"
|
||||||
|
@ -1199,6 +1200,11 @@ crypto-browserify@^3.11.0:
|
||||||
randombytes "^2.0.0"
|
randombytes "^2.0.0"
|
||||||
randomfill "^1.0.3"
|
randomfill "^1.0.3"
|
||||||
|
|
||||||
|
crypto-js@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc"
|
||||||
|
integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==
|
||||||
|
|
||||||
cyclist@^1.0.1:
|
cyclist@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.npm.taobao.org/cyclist/download/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
|
resolved "https://registry.npm.taobao.org/cyclist/download/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@docmirror/dev-sidecar-gui",
|
"name": "@docmirror/dev-sidecar-gui",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -14,8 +14,8 @@
|
||||||
},
|
},
|
||||||
"main": "background.js",
|
"main": "background.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docmirror/dev-sidecar": "^1.2.0",
|
"@docmirror/dev-sidecar": "^1.2.1",
|
||||||
"@docmirror/mitmproxy": "^1.2.0",
|
"@docmirror/mitmproxy": "^1.2.1",
|
||||||
"ant-design-vue": "^1.6.5",
|
"ant-design-vue": "^1.6.5",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"electron-baidu-tongji": "^1.0.5",
|
"electron-baidu-tongji": "^1.0.5",
|
||||||
|
|
|
@ -190,8 +190,8 @@ if (!isFirstInstance) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// updateUrl = 'https://dev-sidecar.docmirror.cn/update/'
|
updateUrl = 'https://dev-sidecar.docmirror.cn/update/'
|
||||||
updateUrl = 'http://localhost/dev-sidecar/'
|
// updateUrl = 'http://localhost/dev-sidecar/'
|
||||||
}
|
}
|
||||||
// 自动更新
|
// 自动更新
|
||||||
updateHandle(app, win, beforeQuit, updateUrl)
|
updateHandle(app, win, beforeQuit, updateUrl)
|
||||||
|
|
|
@ -8,8 +8,7 @@ const pk = require('../../package.json')
|
||||||
const mitmproxyPath = path.join(__dirname, 'mitmproxy.js')
|
const mitmproxyPath = path.join(__dirname, 'mitmproxy.js')
|
||||||
const log = require('../utils/util.log')
|
const log = require('../utils/util.log')
|
||||||
const getDefaultConfigBasePath = function () {
|
const getDefaultConfigBasePath = function () {
|
||||||
const userHome = process.env.HOME || process.env.USERPROFILE
|
return DevSidecar.api.config.get().server.setting.userBasePath
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
|
||||||
}
|
}
|
||||||
const localApi = {
|
const localApi = {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const server = require('@docmirror/mitmproxy')
|
const server = require('@docmirror/mitmproxy')
|
||||||
const config = JSON.parse(process.argv[2])
|
const configPath = process.argv[2]
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const log = require('../utils/util.log')
|
const configJson = fs.readFileSync(configPath)
|
||||||
|
const config = JSON.parse(configJson)
|
||||||
|
|
||||||
let scriptDir = '../extra/scripts/'
|
let scriptDir = '../extra/scripts/'
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
scriptDir = '../extra/scripts/'
|
scriptDir = '../extra/scripts/'
|
||||||
}
|
}
|
||||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||||
log.debug('scriptDir', config.setting.script.defaultDir)
|
|
||||||
server.start(config)
|
server.start(config)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
const log4js = require('log4js')
|
const log4js = require('log4js')
|
||||||
const path = require('path')
|
const DevSidecar = require('@docmirror/dev-sidecar')
|
||||||
const getDefaultConfigBasePath = function () {
|
const getDefaultConfigBasePath = function () {
|
||||||
const userHome = process.env.HOME || process.env.USERPROFILE
|
return DevSidecar.api.config.get().server.setting.userBasePath
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
|
||||||
}
|
}
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/gui.log' } },
|
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: getDefaultConfigBasePath() + '/logs/gui.log' } },
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '../api'
|
|
||||||
export default {
|
export default {
|
||||||
name: 'setup-ca',
|
name: 'setup-ca',
|
||||||
components: {
|
components: {
|
||||||
|
@ -55,7 +54,6 @@ export default {
|
||||||
this.$emit('update:visible', false)
|
this.$emit('update:visible', false)
|
||||||
},
|
},
|
||||||
async doSetup () {
|
async doSetup () {
|
||||||
await api.shell.setupCa()
|
|
||||||
this.$emit('setup')
|
this.$emit('setup')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
let updateParams = { }
|
|
||||||
function install (app, api) {
|
function install (app, api) {
|
||||||
|
const updateParams = app.$global.update = { fromUser: false, autoDownload: true, progress: 0, downloading: false, newVersion: false }
|
||||||
api.ipc.on('update', (event, message) => {
|
api.ipc.on('update', (event, message) => {
|
||||||
console.log('on message', event, message)
|
console.log('on message', event, message)
|
||||||
handleUpdateMessage(message, app)
|
handleUpdateMessage(message, app)
|
||||||
})
|
})
|
||||||
|
|
||||||
api.update = {
|
api.update = {
|
||||||
checkForUpdate (params) {
|
checkForUpdate (fromUser) {
|
||||||
updateParams = params || { fromUser: false, autoDownload: true, progress: 0 }
|
if (fromUser != null) {
|
||||||
|
updateParams.fromUser = fromUser
|
||||||
|
}
|
||||||
api.ipc.send('update', { key: 'checkForUpdate' })
|
api.ipc.send('update', { key: 'checkForUpdate' })
|
||||||
},
|
},
|
||||||
downloadUpdate () {
|
downloadUpdate () {
|
||||||
|
@ -26,6 +29,8 @@ function install (app, api) {
|
||||||
noNewVersion()
|
noNewVersion()
|
||||||
} else if (type === 'downloaded') {
|
} else if (type === 'downloaded') {
|
||||||
// 更新包已下载完成,让用户确认是否更新
|
// 更新包已下载完成,让用户确认是否更新
|
||||||
|
updateParams.downloading = false
|
||||||
|
console.log('updateParams', updateParams)
|
||||||
newUpdateIsReady(message.value)
|
newUpdateIsReady(message.value)
|
||||||
} else if (type === 'progress') {
|
} else if (type === 'progress') {
|
||||||
progressUpdate(message.value)
|
progressUpdate(message.value)
|
||||||
|
@ -50,6 +55,7 @@ function install (app, api) {
|
||||||
|
|
||||||
if (updateParams.autoDownload !== false) {
|
if (updateParams.autoDownload !== false) {
|
||||||
app.$message.info('发现新版本,正在下载中...')
|
app.$message.info('发现新版本,正在下载中...')
|
||||||
|
updateParams.downloading = true
|
||||||
api.update.downloadUpdate()
|
api.update.downloadUpdate()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,6 +76,7 @@ function install (app, api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function newUpdateIsReady (value) {
|
function newUpdateIsReady (value) {
|
||||||
|
updateParams.downloading = false
|
||||||
app.$confirm({
|
app.$confirm({
|
||||||
title: '新版本已准备好',
|
title: '新版本已准备好',
|
||||||
content: `是否立即升级安装v${value.version}?`,
|
content: `是否立即升级安装v${value.version}?`,
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
<a-badge :count="_rootCaSetuped?0:1" dot>安装根证书 </a-badge>
|
<a-badge :count="_rootCaSetuped?0:1" dot>安装根证书 </a-badge>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|
||||||
<a-button style="margin-right:10px" @click="doCheckUpdate" :title="'当前版本:'+info.version">
|
<a-button style="margin-right:10px" @click="doCheckUpdate(true)" :loading="update.downloading" :title="'当前版本:'+info.version">
|
||||||
<a-badge :count="update.newVersion?1:0" dot>
|
<a-badge :count="update.newVersion?1:0" dot>
|
||||||
检查更新
|
<span v-if="update.downloading">{{update.progress}}%</span>{{update.downloading?'新版本下载中':'检查更新'}}
|
||||||
</a-badge>
|
</a-badge>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<a-form style="margin-top:20px" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
|
<a-form style="margin-top:20px" :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }">
|
||||||
|
|
||||||
<a-form-item v-for=" (item, key) in switchBtns" :key="key" :label="item.label">
|
<a-form-item v-for=" (item, key) in switchBtns" :key="key" :label="item.label">
|
||||||
<a-switch style="margin-left:10px" :loading="item.loading" v-model="item.status[key].enabled" default-checked v-on:click="item.doClick">
|
<a-switch style="margin-left:10px" :loading="item.loading" :checked="item.status()" default-checked @change="item.doClick">
|
||||||
<a-icon slot="checkedChildren" type="check"/>
|
<a-icon slot="checkedChildren" type="check"/>
|
||||||
<a-icon slot="unCheckedChildren" type="close"/>
|
<a-icon slot="unCheckedChildren" type="close"/>
|
||||||
</a-switch>
|
</a-switch>
|
||||||
|
@ -57,7 +57,6 @@
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
import setupCa from '../components/setup-ca'
|
import setupCa from '../components/setup-ca'
|
||||||
import DsContainer from '../components/container'
|
import DsContainer from '../components/container'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Index',
|
name: 'Index',
|
||||||
components: {
|
components: {
|
||||||
|
@ -89,6 +88,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
info: {},
|
info: {},
|
||||||
|
newVersionDownloading: false,
|
||||||
setting: undefined,
|
setting: undefined,
|
||||||
server: {
|
server: {
|
||||||
key: '代理服务',
|
key: '代理服务',
|
||||||
|
@ -102,30 +102,20 @@ export default {
|
||||||
setupCa: {
|
setupCa: {
|
||||||
visible: false
|
visible: false
|
||||||
},
|
},
|
||||||
update: {}
|
update: { downloading: false, progress: 0, newVersion: false }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
this.doCheckRootCa()
|
this.doCheckRootCa()
|
||||||
console.log('index created', this.status, this.$status)
|
|
||||||
await this.reloadConfig()
|
await this.reloadConfig()
|
||||||
const status = await this.$api.status.get()
|
this.$set(this, 'status', this.$status)
|
||||||
console.log('status', status)
|
|
||||||
this.$set(this, 'status', status)
|
|
||||||
this.switchBtns = this.createSwitchBtns()
|
this.switchBtns = this.createSwitchBtns()
|
||||||
console.log('switchBtns', this.switchBtns)
|
console.log('switchBtns', this.switchBtns)
|
||||||
if (this.$global.update == null) {
|
this.$set(this, 'update', this.$global.update)
|
||||||
this.$global.update = {
|
if (!this.update.autoChecked) {
|
||||||
fromUser: false,
|
this.update.autoChecked = true
|
||||||
autoDownload: true,
|
|
||||||
progress: 0,
|
|
||||||
newVersion: false
|
|
||||||
}
|
|
||||||
this.update = this.$global.update
|
|
||||||
this.doCheckUpdate(false)
|
this.doCheckUpdate(false)
|
||||||
}
|
}
|
||||||
this.update = this.$global.update
|
|
||||||
|
|
||||||
this.$api.info.get().then(ret => {
|
this.$api.info.get().then(ret => {
|
||||||
this.info = ret
|
this.info = ret
|
||||||
})
|
})
|
||||||
|
@ -161,7 +151,9 @@ export default {
|
||||||
openSetupCa () {
|
openSetupCa () {
|
||||||
this.setupCa.visible = true
|
this.setupCa.visible = true
|
||||||
},
|
},
|
||||||
handleCaSetuped () {
|
async handleCaSetuped () {
|
||||||
|
console.log('this.config.server.setting.rootCaFile.certPath', this.config.server.setting.rootCaFile.certPath)
|
||||||
|
await this.$api.shell.setupCa({ certPath: this.config.server.setting.rootCaFile.certPath })
|
||||||
this.setting.rootCa = this.setting.rootCa || {}
|
this.setting.rootCa = this.setting.rootCa || {}
|
||||||
const rootCa = this.setting.rootCa
|
const rootCa = this.setting.rootCa
|
||||||
rootCa.setuped = true
|
rootCa.setuped = true
|
||||||
|
@ -190,7 +182,9 @@ export default {
|
||||||
loading: false,
|
loading: false,
|
||||||
key: key,
|
key: key,
|
||||||
label: label,
|
label: label,
|
||||||
status: statusParent,
|
status: () => {
|
||||||
|
return statusParent[key].enabled
|
||||||
|
},
|
||||||
doClick: (checked) => {
|
doClick: (checked) => {
|
||||||
this.onSwitchClick(this.switchBtns[key], apiTarget.start, apiTarget.close, checked)
|
this.onSwitchClick(this.switchBtns[key], apiTarget.start, apiTarget.close, checked)
|
||||||
}
|
}
|
||||||
|
@ -234,8 +228,7 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
doCheckUpdate (fromUser = true) {
|
doCheckUpdate (fromUser = true) {
|
||||||
this.update.fromUser = fromUser
|
this.$api.update.checkForUpdate(fromUser)
|
||||||
this.$api.update.checkForUpdate(this.update)
|
|
||||||
},
|
},
|
||||||
openExternal (url) {
|
openExternal (url) {
|
||||||
this.$api.ipc.openExternal(url)
|
this.$api.ipc.openExternal(url)
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
</a-checkbox>
|
</a-checkbox>
|
||||||
<div>开启此项之后,被代理应用关闭SSL校验也问题不大了</div>
|
<div>开启此项之后,被代理应用关闭SSL校验也问题不大了</div>
|
||||||
</a-form-item>
|
</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-form-item>
|
||||||
<a-form-item label="启用脚本" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-form-item label="启用脚本" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-tooltip title="关闭后,github的clone加速链接复制也将关闭">
|
<a-tooltip title="关闭后,github的clone加速链接复制也将关闭">
|
||||||
<a-checkbox v-model="config.server.setting.script.enabled" >
|
<a-checkbox v-model="config.server.setting.script.enabled" >
|
||||||
|
|
|
@ -901,12 +901,12 @@
|
||||||
ajv "^6.12.0"
|
ajv "^6.12.0"
|
||||||
ajv-keywords "^3.4.1"
|
ajv-keywords "^3.4.1"
|
||||||
|
|
||||||
"@docmirror/dev-sidecar@^1.1.0":
|
"@docmirror/dev-sidecar@^1.2.0":
|
||||||
version "1.1.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.1.0.tgz#a77fbbacceedd62202aea581712b13595629756f"
|
resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.0.tgz#2320c31f786afd495b8e12557bea396cb96e0985"
|
||||||
integrity sha512-Amh8m7nArLUvDL7QAfNV4rTaZIOOyS4/DY4+9h/1B9RXRFJ4oGePcBkH6QXO3p0msoutu87BtYXFTl0qvY4vQQ==
|
integrity sha512-i96YlPjQtrrAgDW52YOpuVFmQDl1A0Nx3x6/riv2yKVN4nGqAugdJvcAuhNi7BDrJfdLyls2jI35uzN5+bpYfQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@docmirror/mitmproxy" "^1.1.0"
|
"@docmirror/mitmproxy" "^1.2.0"
|
||||||
agentkeepalive "^2.1.1"
|
agentkeepalive "^2.1.1"
|
||||||
charset "^1.0.0"
|
charset "^1.0.0"
|
||||||
child_process "^1.0.2"
|
child_process "^1.0.2"
|
||||||
|
@ -920,6 +920,7 @@
|
||||||
jschardet "^1.4.1"
|
jschardet "^1.4.1"
|
||||||
json5 "^2.1.3"
|
json5 "^2.1.3"
|
||||||
lodash "^4.7.0"
|
lodash "^4.7.0"
|
||||||
|
log4js "^6.3.0"
|
||||||
lru-cache "^6.0.0"
|
lru-cache "^6.0.0"
|
||||||
mkdirp "^0.5.1"
|
mkdirp "^0.5.1"
|
||||||
node-cmd "^3.0.0"
|
node-cmd "^3.0.0"
|
||||||
|
@ -932,15 +933,16 @@
|
||||||
validator "^13.1.17"
|
validator "^13.1.17"
|
||||||
winreg "^1.2.4"
|
winreg "^1.2.4"
|
||||||
|
|
||||||
"@docmirror/mitmproxy@^1.1.0":
|
"@docmirror/mitmproxy@^1.2.0":
|
||||||
version "1.1.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.1.0.tgz#d2dfa4c8047306c40105e0673365fdb4182be39b"
|
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e"
|
||||||
integrity sha512-KgNQ24o18G3Gnw9F9EkKKIKuEf3EnHh2uASMs72HvmuLobZo+D+0L+lL2xYPp+w5t8aXt0bgQeK8lRcz2C6wWw==
|
integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg==
|
||||||
dependencies:
|
dependencies:
|
||||||
agentkeepalive "^2.1.1"
|
agentkeepalive "^2.1.1"
|
||||||
child_process "^1.0.2"
|
child_process "^1.0.2"
|
||||||
colors "^1.1.2"
|
colors "^1.1.2"
|
||||||
commander "^2.9.0"
|
commander "^2.9.0"
|
||||||
|
crypto-js "^4.0.0"
|
||||||
debug "^4.1.1"
|
debug "^4.1.1"
|
||||||
dns-over-http "^0.2.0"
|
dns-over-http "^0.2.0"
|
||||||
dns-over-tls "^0.0.8"
|
dns-over-tls "^0.0.8"
|
||||||
|
@ -3729,6 +3731,11 @@ crypto-browserify@^3.11.0:
|
||||||
randombytes "^2.0.0"
|
randombytes "^2.0.0"
|
||||||
randomfill "^1.0.3"
|
randomfill "^1.0.3"
|
||||||
|
|
||||||
|
crypto-js@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc"
|
||||||
|
integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==
|
||||||
|
|
||||||
crypto-random-string@^2.0.0:
|
crypto-random-string@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.npm.taobao.org/crypto-random-string/download/crypto-random-string-2.0.0.tgz?cache=0&sync_timestamp=1599139352103&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-random-string%2Fdownload%2Fcrypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5"
|
resolved "https://registry.npm.taobao.org/crypto-random-string/download/crypto-random-string-2.0.0.tgz?cache=0&sync_timestamp=1599139352103&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-random-string%2Fdownload%2Fcrypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@docmirror/mitmproxy",
|
"name": "@docmirror/mitmproxy",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@docmirror/mitmproxy",
|
"name": "@docmirror/mitmproxy",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
const mitmproxy = require('./lib/proxy')
|
const mitmproxy = require('./lib/proxy')
|
||||||
const ProxyOptions = require('./options')
|
const ProxyOptions = require('./options')
|
||||||
const config = require('./lib/proxy/common/config')
|
const proxyConfig = require('./lib/proxy/common/config')
|
||||||
const log = require('./utils/util.log')
|
const log = require('./utils/util.log')
|
||||||
function fireError (e) {
|
const { fireError, fireStatus } = require('./utils/util.process')
|
||||||
process.send({ type: 'error', event: e })
|
|
||||||
}
|
|
||||||
function fireStatus (status) {
|
|
||||||
process.send({ type: 'status', event: status })
|
|
||||||
}
|
|
||||||
|
|
||||||
let server
|
let server
|
||||||
|
|
||||||
|
@ -42,6 +37,13 @@ function registerProcessListener () {
|
||||||
const api = {
|
const api = {
|
||||||
async start (config) {
|
async start (config) {
|
||||||
const proxyOptions = ProxyOptions(config)
|
const proxyOptions = ProxyOptions(config)
|
||||||
|
const setting = config.setting
|
||||||
|
if (setting) {
|
||||||
|
if (setting.userBasePath) {
|
||||||
|
proxyConfig.setDefaultCABasePath(setting.userBasePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (proxyOptions.setting && proxyOptions.setting.NODE_TLS_REJECT_UNAUTHORIZED === false) {
|
if (proxyOptions.setting && proxyOptions.setting.NODE_TLS_REJECT_UNAUTHORIZED === false) {
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
} else {
|
} else {
|
||||||
|
@ -95,5 +97,6 @@ const api = {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...api,
|
...api,
|
||||||
config
|
config: proxyConfig,
|
||||||
|
log
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ module.exports = {
|
||||||
const { rOptions, log, RequestCounter } = context
|
const { rOptions, log, RequestCounter } = context
|
||||||
|
|
||||||
let proxyConf = interceptOpt.proxy
|
let proxyConf = interceptOpt.proxy
|
||||||
if (RequestCounter) {
|
if (RequestCounter && interceptOpt.backup) {
|
||||||
// 优选逻辑
|
// 优选逻辑
|
||||||
const backup = [proxyConf]
|
const backup = [proxyConf]
|
||||||
if (interceptOpt.backup) {
|
if (interceptOpt.backup) {
|
||||||
|
@ -12,7 +12,6 @@ module.exports = {
|
||||||
backup.push(bk)
|
backup.push(bk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
backup.push(rOptions.hostname)
|
|
||||||
|
|
||||||
const key = interceptOpt.key
|
const key = interceptOpt.key
|
||||||
const count = RequestCounter.getOrCreate(key, backup)
|
const count = RequestCounter.getOrCreate(key, backup)
|
||||||
|
|
|
@ -9,8 +9,16 @@ config.defaultPort = 1181
|
||||||
|
|
||||||
config.caName = 'This certificate is generated locally'
|
config.caName = 'This certificate is generated locally'
|
||||||
|
|
||||||
|
config.caBasePath = buildDefaultCABasePath()
|
||||||
|
|
||||||
config.getDefaultCABasePath = function () {
|
config.getDefaultCABasePath = function () {
|
||||||
const userHome = process.env.HOME || process.env.USERPROFILE
|
return config.caBasePath
|
||||||
|
}
|
||||||
|
config.setDefaultCABasePath = function (path) {
|
||||||
|
config.caBasePath = path
|
||||||
|
}
|
||||||
|
function buildDefaultCABasePath () {
|
||||||
|
const userHome = process.env.USERPROFILE
|
||||||
return path.resolve(userHome, './.dev-sidecar')
|
return path.resolve(userHome, './.dev-sidecar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,18 @@ module.exports = {
|
||||||
}, callback) {
|
}, callback) {
|
||||||
// Don't reject unauthorized
|
// Don't reject unauthorized
|
||||||
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
|
log.info(`CA Cert read in: ${caCertPath}`)
|
||||||
if (!caCertPath && !caKeyPath) {
|
log.info(`CA private key read in: ${caKeyPath}`)
|
||||||
const rs = this.createCA()
|
if (!caCertPath) {
|
||||||
caCertPath = rs.caCertPath
|
caCertPath = config.getDefaultCACertPath()
|
||||||
caKeyPath = rs.caKeyPath
|
}
|
||||||
if (rs.create) {
|
if (!caKeyPath) {
|
||||||
log.info(`CA Cert saved in: ${caCertPath}`)
|
caKeyPath = config.getDefaultCAKeyPath()
|
||||||
log.info(`CA private key saved in: ${caKeyPath}`)
|
}
|
||||||
}
|
const rs = this.createCA({ caCertPath, caKeyPath })
|
||||||
|
if (rs.create) {
|
||||||
|
log.info(`CA Cert saved in: ${caCertPath}`)
|
||||||
|
log.info(`CA private key saved in: ${caKeyPath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
port = ~~port
|
port = ~~port
|
||||||
|
@ -88,7 +91,7 @@ module.exports = {
|
||||||
})
|
})
|
||||||
return server
|
return server
|
||||||
},
|
},
|
||||||
createCA (caBasePath = config.getDefaultCABasePath()) {
|
createCA (caPaths) {
|
||||||
return tlsUtils.initCA(caBasePath)
|
return tlsUtils.initCA(caPaths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,10 +237,7 @@ utils.getMappingHostNamesFormCert = function (cert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync
|
// sync
|
||||||
utils.initCA = function (basePath = config.getDefaultCABasePath()) {
|
utils.initCA = function ({ caCertPath, caKeyPath }) {
|
||||||
const caCertPath = path.resolve(basePath, config.caCertFileName)
|
|
||||||
const caKeyPath = path.resolve(basePath, config.caKeyFileName)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.accessSync(caCertPath, fs.F_OK)
|
fs.accessSync(caCertPath, fs.F_OK)
|
||||||
fs.accessSync(caKeyPath, fs.F_OK)
|
fs.accessSync(caKeyPath, fs.F_OK)
|
||||||
|
|
|
@ -48,13 +48,14 @@ module.exports = (config) => {
|
||||||
|
|
||||||
const dnsMapping = config.dns.mapping
|
const dnsMapping = config.dns.mapping
|
||||||
const serverConfig = config
|
const serverConfig = config
|
||||||
return {
|
const setting = serverConfig.setting
|
||||||
|
const options = {
|
||||||
port: serverConfig.port,
|
port: serverConfig.port,
|
||||||
dnsConfig: {
|
dnsConfig: {
|
||||||
providers: dnsUtil.initDNS(serverConfig.dns.providers),
|
providers: dnsUtil.initDNS(serverConfig.dns.providers),
|
||||||
mapping: dnsMapping
|
mapping: dnsMapping
|
||||||
},
|
},
|
||||||
setting: serverConfig.setting,
|
setting,
|
||||||
sslConnectInterceptor: (req, cltSocket, head) => {
|
sslConnectInterceptor: (req, cltSocket, head) => {
|
||||||
const hostname = req.url.split(':')[0]
|
const hostname = req.url.split(':')[0]
|
||||||
const inWhiteList = matchHostname(whiteList, hostname) != null
|
const inWhiteList = matchHostname(whiteList, hostname) != null
|
||||||
|
@ -103,4 +104,10 @@ module.exports = (config) => {
|
||||||
return matchIntercepts
|
return matchIntercepts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting.rootCaFile) {
|
||||||
|
options.caCertPath = setting.rootCaFile.certPath
|
||||||
|
options.caKeyPath = setting.rootCaFile.keyPath
|
||||||
|
}
|
||||||
|
return options
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
module.exports = {
|
||||||
|
fireError (e) {
|
||||||
|
process.send({ type: 'error', event: e })
|
||||||
|
},
|
||||||
|
fireStatus (status) {
|
||||||
|
process.send({ type: 'status', event: status })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue