refactor: mirrors
parent
62c023875a
commit
651a509069
|
@ -6,6 +6,5 @@
|
||||||
"lerna": "^3.22.1"
|
"lerna": "^3.22.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sqlite3": "^5.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1116,6 +1116,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@coolaj86/urequest": {
|
||||||
|
"version": "1.3.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@coolaj86/urequest/-/urequest-1.3.7.tgz",
|
||||||
|
"integrity": "sha512-PPrVYra9aWvZjSCKl/x1pJ9ZpXda1652oJrPBYy5rQumJJMkmTBN3ux+sK2xAUwVvv2wnewDlaQaHLxLwSHnIA=="
|
||||||
|
},
|
||||||
"@hapi/address": {
|
"@hapi/address": {
|
||||||
"version": "2.1.4",
|
"version": "2.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz",
|
||||||
|
@ -1795,6 +1800,7 @@
|
||||||
"thread-loader": "^2.1.3",
|
"thread-loader": "^2.1.3",
|
||||||
"url-loader": "^2.2.0",
|
"url-loader": "^2.2.0",
|
||||||
"vue-loader": "^15.9.2",
|
"vue-loader": "^15.9.2",
|
||||||
|
"vue-loader-v16": "npm:vue-loader@^16.0.0-beta.7",
|
||||||
"vue-style-loader": "^4.1.2",
|
"vue-style-loader": "^4.1.2",
|
||||||
"webpack": "^4.0.0",
|
"webpack": "^4.0.0",
|
||||||
"webpack-bundle-analyzer": "^3.8.0",
|
"webpack-bundle-analyzer": "^3.8.0",
|
||||||
|
@ -11417,6 +11423,14 @@
|
||||||
"tweetnacl": "~0.14.0"
|
"tweetnacl": "~0.14.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ssl-root-cas": {
|
||||||
|
"version": "1.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ssl-root-cas/-/ssl-root-cas-1.3.1.tgz",
|
||||||
|
"integrity": "sha512-KR8J210Wfvjh+iNE9jcQEgbG0VG2713PHreItx6aNCPnkFO8XChz1cJ4iuCGeBj0+8wukLmgHgJqX+O5kRjPkQ==",
|
||||||
|
"requires": {
|
||||||
|
"@coolaj86/urequest": "^1.3.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ssri": {
|
"ssri": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
|
||||||
|
@ -12414,6 +12428,63 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"vue-loader-v16": {
|
||||||
|
"version": "npm:vue-loader@16.0.0-beta.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.0.0-beta.9.tgz",
|
||||||
|
"integrity": "sha512-mu9pg6554GbXDSO8LlxkQM6qUJzUkb/A0FJc9LgRqnU9MCnhzEXwCt1Zx5NObvFpzs2mH2dH/uUCDwL8Qaz9sA==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
|
"requires": {
|
||||||
|
"chalk": "^4.1.0",
|
||||||
|
"hash-sum": "^2.0.0",
|
||||||
|
"loader-utils": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": {
|
||||||
|
"version": "4.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
|
"requires": {
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chalk": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
|
"requires": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
|
"requires": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"loader-utils": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
|
"requires": {
|
||||||
|
"big.js": "^5.2.2",
|
||||||
|
"emojis-list": "^3.0.0",
|
||||||
|
"json5": "^2.1.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"vue-style-loader": {
|
"vue-style-loader": {
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz",
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
"node-mitmproxy": "^3.1.1",
|
"node-mitmproxy": "^3.1.1",
|
||||||
"node-powershell": "^4.0.0",
|
"node-powershell": "^4.0.0",
|
||||||
"require-context": "^1.1.0",
|
"require-context": "^1.1.0",
|
||||||
|
"ssl-root-cas": "^1.3.1",
|
||||||
"through2": "^2.0.1",
|
"through2": "^2.0.1",
|
||||||
"tunnel-agent": "^0.4.3",
|
"tunnel-agent": "^0.4.3",
|
||||||
"util": "^0.12.3",
|
"util": "^0.12.3",
|
||||||
|
|
|
@ -42,14 +42,15 @@ module.exports = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// google cdn
|
// google cdn
|
||||||
|
// https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
|
||||||
'ajax.googleapis.com': [
|
'ajax.googleapis.com': [
|
||||||
{
|
{
|
||||||
proxy: 'https://ajax.loli.net'
|
proxy: 'https://ajax.proxy.ustclug.org'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'fonts.googleapis.com': [
|
'fonts.googleapis.com': [
|
||||||
{
|
{
|
||||||
proxy: 'https://fonts.loli.net'
|
proxy: 'https://fonts.proxy.ustclug.org'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'themes.googleapis.com': [
|
'themes.googleapis.com': [
|
||||||
|
@ -59,7 +60,7 @@ module.exports = {
|
||||||
],
|
],
|
||||||
'fonts.gstatic.com': [
|
'fonts.gstatic.com': [
|
||||||
{
|
{
|
||||||
proxy: 'https://gstatic.loli.net'
|
proxy: 'https://fonts-gstatic.proxy.ustclug.org'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'www.google.com': [
|
'www.google.com': [
|
||||||
|
@ -68,28 +69,24 @@ module.exports = {
|
||||||
proxy: 'https://www.recaptcha.net'
|
proxy: 'https://www.recaptcha.net'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'secure.gravatar.com': [
|
'clients*.google.com': [{ abort: true }],
|
||||||
{
|
'www.googleapis.com': [{ abort: true }],
|
||||||
redirect: 'https://gravatar.loli.net'
|
'lh*.googleusercontent.com': [{ abort: true }],
|
||||||
}
|
|
||||||
],
|
|
||||||
'clients*.google.com': [
|
|
||||||
{
|
|
||||||
abort: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'lh*.googleusercontent.com': [
|
|
||||||
{
|
|
||||||
abort: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.0/napi-v3-win32-x64.tar.gz
|
// https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.0/napi-v3-win32-x64.tar.gz
|
||||||
'*.s3.amazonaws.com': [
|
'*.s3.amazonaws.com': [
|
||||||
{
|
{
|
||||||
regexp: '/sqlite3/.*',
|
regexp: '/sqlite3/.*',
|
||||||
redirect: 'http://npm.taobao.org/mirrors'
|
redirect: 'http://npm.taobao.org/mirrors'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'registry-1.docker.io': [{ proxy: 'docker.mirrors.ustc.edu.cn' }],
|
||||||
|
'packages.elastic.co': [{ proxy: 'elastic.proxy.ustclug.org' }],
|
||||||
|
'ppa.launchpad.net': [{ proxy: 'launchpad.proxy.ustclug.org' }],
|
||||||
|
'archive.cloudera.com': [{ regexp: '/cdh5/.*', proxy: 'cloudera.proxy.ustclug.org' }],
|
||||||
|
'downloads.lede-project.org': [{ proxy: 'lede.proxy.ustclug.org' }],
|
||||||
|
'downloads.openwrt.org': [{ proxy: 'openwrt.proxy.ustclug.org' }],
|
||||||
|
'themes.googleusercontent.com': [{ proxy: 'google-themes.proxy.ustclug.org' }],
|
||||||
|
'secure.gravatar.com': [{ proxy: 'gravatar.proxy.ustclug.org' }]
|
||||||
},
|
},
|
||||||
dns: {
|
dns: {
|
||||||
providers: {
|
providers: {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
requestInterceptor (interceptOpt, rOptions, req, res, ssl) {
|
requestInterceptor (interceptOpt, rOptions, req, res, ssl) {
|
||||||
req.abort()
|
|
||||||
console.log('abort:', rOptions.hostname, req.url)
|
console.log('abort:', rOptions.hostname, req.url)
|
||||||
|
req.destroy()
|
||||||
},
|
},
|
||||||
is (interceptOpt) {
|
is (interceptOpt) {
|
||||||
return !!interceptOpt.abort
|
return !!interceptOpt.abort
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
const url = require('url')
|
const url = require('url')
|
||||||
module.exports = {
|
module.exports = {
|
||||||
requestInterceptor (interceptOpt, rOptions, req, res, ssl) {
|
requestInterceptor (interceptOpt, rOptions, req, res, ssl) {
|
||||||
|
const proxy = interceptOpt.proxy.indexOf('http') === 0 ? interceptOpt.proxy : rOptions.protocol + '//' + interceptOpt.proxy
|
||||||
// eslint-disable-next-line node/no-deprecated-api
|
// eslint-disable-next-line node/no-deprecated-api
|
||||||
const URL = url.parse(interceptOpt.proxy)
|
const URL = url.parse(proxy)
|
||||||
rOptions.protocol = URL.protocol
|
rOptions.protocol = URL.protocol
|
||||||
rOptions.hostname = URL.host
|
rOptions.hostname = URL.host
|
||||||
rOptions.host = URL.host
|
rOptions.host = URL.host
|
||||||
|
|
|
@ -9,7 +9,6 @@ module.exports = function createConnectHandler (sslConnectInterceptor, fakeServe
|
||||||
return function connectHandler (req, cltSocket, head) {
|
return function connectHandler (req, cltSocket, head) {
|
||||||
// eslint-disable-next-line node/no-deprecated-api
|
// eslint-disable-next-line node/no-deprecated-api
|
||||||
const srvUrl = url.parse(`https://${req.url}`)
|
const srvUrl = url.parse(`https://${req.url}`)
|
||||||
|
|
||||||
const hostname = srvUrl.hostname
|
const hostname = srvUrl.hostname
|
||||||
if (typeof sslConnectInterceptor === 'function' && sslConnectInterceptor(req, cltSocket, head)) {
|
if (typeof sslConnectInterceptor === 'function' && sslConnectInterceptor(req, cltSocket, head)) {
|
||||||
fakeServerCenter.getServerPromise(hostname, srvUrl.port).then((serverObj) => {
|
fakeServerCenter.getServerPromise(hostname, srvUrl.port).then((serverObj) => {
|
||||||
|
|
|
@ -11,7 +11,6 @@ module.exports = function createRequestHandler (requestInterceptor, responseInte
|
||||||
let proxyReq
|
let proxyReq
|
||||||
|
|
||||||
const rOptions = commonUtil.getOptionsFormRequest(req, ssl, externalProxy)
|
const rOptions = commonUtil.getOptionsFormRequest(req, ssl, externalProxy)
|
||||||
|
|
||||||
if (rOptions.headers.connection === 'close') {
|
if (rOptions.headers.connection === 'close') {
|
||||||
req.socket.setKeepAlive(false)
|
req.socket.setKeepAlive(false)
|
||||||
} else if (rOptions.customSocketId != null) { // for NTLM
|
} else if (rOptions.customSocketId != null) { // for NTLM
|
||||||
|
@ -63,9 +62,7 @@ module.exports = function createRequestHandler (requestInterceptor, responseInte
|
||||||
function onFree () {
|
function onFree () {
|
||||||
const url = `${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`
|
const url = `${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`
|
||||||
const start = new Date().getTime()
|
const start = new Date().getTime()
|
||||||
if (rOptions.protocol === 'https:') {
|
console.log('代理请求:', url)
|
||||||
console.log('代理请求:', url)
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyReq = (rOptions.protocol === 'https:' ? https : http).request(rOptions, (proxyRes) => {
|
proxyReq = (rOptions.protocol === 'https:' ? https : http).request(rOptions, (proxyRes) => {
|
||||||
const end = new Date().getTime()
|
const end = new Date().getTime()
|
||||||
|
@ -76,12 +73,12 @@ module.exports = function createRequestHandler (requestInterceptor, responseInte
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('timeout', () => {
|
proxyReq.on('timeout', () => {
|
||||||
console.error('代理请求超时', rOptions.host, rOptions.path)
|
console.error('代理请求超时', rOptions.hostname, rOptions.path)
|
||||||
reject(new Error(`${rOptions.host}:${rOptions.port}, 代理请求超时`))
|
reject(new Error(`${rOptions.host}:${rOptions.port}, 代理请求超时`))
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('error', (e, req, res) => {
|
proxyReq.on('error', (e, req, res) => {
|
||||||
console.error('代理请求错误', e.errno, rOptions.host, rOptions.path)
|
console.error('代理请求错误', e.errno, rOptions.hostname, rOptions.path)
|
||||||
reject(e)
|
reject(e)
|
||||||
if (res) {
|
if (res) {
|
||||||
res.end()
|
res.end()
|
||||||
|
@ -89,26 +86,26 @@ module.exports = function createRequestHandler (requestInterceptor, responseInte
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('aborted', () => {
|
proxyReq.on('aborted', () => {
|
||||||
console.error('代理请求被取消', rOptions.host, rOptions.path)
|
console.error('代理请求被取消', rOptions.hostname, rOptions.path)
|
||||||
reject(new Error('代理请求被取消'))
|
reject(new Error('代理请求被取消'))
|
||||||
req.abort()
|
req.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
req.on('aborted', function () {
|
req.on('aborted', function () {
|
||||||
console.error('请求被取消', rOptions.host, rOptions.path)
|
console.error('请求被取消', rOptions.hostname, rOptions.path)
|
||||||
proxyReq.abort()
|
proxyReq.destroy()
|
||||||
reject(new Error('请求被取消'))
|
reject(new Error('请求被取消'))
|
||||||
})
|
})
|
||||||
req.on('error', function (e, req, res) {
|
req.on('error', function (e, req, res) {
|
||||||
console.error('请求错误:', e.errno, rOptions.host, rOptions.path)
|
console.error('请求错误:', e.errno, rOptions.hostname, rOptions.path)
|
||||||
reject(e)
|
reject(e)
|
||||||
if (res) {
|
if (res) {
|
||||||
res.end()
|
res.end()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
req.on('timeout', () => {
|
req.on('timeout', () => {
|
||||||
console.error('请求超时', rOptions.host, rOptions.path)
|
console.error('请求超时', rOptions.hostname, rOptions.path)
|
||||||
reject(new Error(`${rOptions.host}:${rOptions.port}, 请求超时`))
|
reject(new Error(`${rOptions.hostname}:${rOptions.port}, 请求超时`))
|
||||||
})
|
})
|
||||||
req.pipe(proxyReq)
|
req.pipe(proxyReq)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports = {
|
||||||
dnsConfig
|
dnsConfig
|
||||||
}, callback) {
|
}, callback) {
|
||||||
// Don't reject unauthorized
|
// Don't reject unauthorized
|
||||||
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
|
|
||||||
if (!caCertPath && !caKeyPath) {
|
if (!caCertPath && !caKeyPath) {
|
||||||
const rs = this.createCA()
|
const rs = this.createCA()
|
||||||
|
@ -65,10 +65,12 @@ module.exports = {
|
||||||
})
|
})
|
||||||
server.on('request', (req, res) => {
|
server.on('request', (req, res) => {
|
||||||
const ssl = false
|
const ssl = false
|
||||||
|
// console.log('request,', req.url, req.port, req.host)
|
||||||
requestHandler(req, res, ssl)
|
requestHandler(req, res, ssl)
|
||||||
})
|
})
|
||||||
// tunneling for https
|
// tunneling for https
|
||||||
server.on('connect', (req, cltSocket, head) => {
|
server.on('connect', (req, cltSocket, head) => {
|
||||||
|
// console.log('connect,', req.url)
|
||||||
connectHandler(req, cltSocket, head)
|
connectHandler(req, cltSocket, head)
|
||||||
})
|
})
|
||||||
// TODO: handler WebSocket
|
// TODO: handler WebSocket
|
||||||
|
|
|
@ -64,6 +64,7 @@ module.exports = class FakeServersCenter {
|
||||||
SNICallback: (hostname, done) => {
|
SNICallback: (hostname, done) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const certObj = await this.certAndKeyContainer.getCertPromise(hostname, port)
|
const certObj = await this.certAndKeyContainer.getCertPromise(hostname, port)
|
||||||
|
console.log('sni callback:', hostname)
|
||||||
done(null, tls.createSecureContext({
|
done(null, tls.createSecureContext({
|
||||||
key: pki.privateKeyToPem(certObj.key),
|
key: pki.privateKeyToPem(certObj.key),
|
||||||
cert: pki.certificateToPem(certObj.cert)
|
cert: pki.certificateToPem(certObj.cert)
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
const ProxyOptions = require('./options')
|
const ProxyOptions = require('./options')
|
||||||
const mitmproxy = require('../lib/proxy')
|
const mitmproxy = require('../lib/proxy')
|
||||||
const getLogger = require('../lib/utils/logger')
|
|
||||||
const logger = getLogger('proxy')
|
|
||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
const event = require('../event')
|
const event = require('../event')
|
||||||
let server
|
let server
|
||||||
const serverApi = {
|
const serverApi = {
|
||||||
async start (newConfig) {
|
async start (newConfig) {
|
||||||
|
if (server != null) {
|
||||||
|
server.close()
|
||||||
|
}
|
||||||
config.set(newConfig)
|
config.set(newConfig)
|
||||||
const proxyOptions = ProxyOptions(config.get())
|
const proxyOptions = ProxyOptions(config.get())
|
||||||
server = mitmproxy.createProxy(proxyOptions, () => {
|
server = mitmproxy.createProxy(proxyOptions, () => {
|
||||||
|
@ -22,21 +23,22 @@ const serverApi = {
|
||||||
return server.config
|
return server.config
|
||||||
},
|
},
|
||||||
async close () {
|
async close () {
|
||||||
try {
|
return new Promise((resolve, reject) => {
|
||||||
if (server) {
|
if (server) {
|
||||||
return new Promise((resolve, reject) => {
|
server.close((err) => {
|
||||||
server.close((err) => {
|
if (err) {
|
||||||
if (err) {
|
console.log('close error', err)
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
server = null
|
||||||
|
} else {
|
||||||
|
console.log('server is null')
|
||||||
|
resolve()
|
||||||
}
|
}
|
||||||
} catch (err) {
|
})
|
||||||
logger.error(err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async restart () {
|
async restart () {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -26,7 +26,6 @@ function isMatched (url, regexp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (config) => {
|
module.exports = (config) => {
|
||||||
console.log('config', config)
|
|
||||||
return {
|
return {
|
||||||
port: config.server.port,
|
port: config.server.port,
|
||||||
dnsConfig: {
|
dnsConfig: {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
const cmd1 = require('node-cmd')
|
// const cmd1 = require('node-cmd')
|
||||||
cmd1.get('set',
|
// cmd1.get('set',
|
||||||
function (err, data, stderr) {
|
// function (err, data, stderr) {
|
||||||
console.log('cmd complete:', err, data, stderr)
|
// console.log('cmd complete:', err, data, stderr)
|
||||||
if (err) {
|
// if (err) {
|
||||||
console.error('cmd 命令执行错误:', err, stderr)
|
// console.error('cmd 命令执行错误:', err, stderr)
|
||||||
} else {
|
// } else {
|
||||||
console.log('cmd 命令执行结果:', data)
|
// console.log('cmd 命令执行结果:', data)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
|
|
||||||
// var process = require('child_process')
|
// var process = require('child_process')
|
||||||
//
|
//
|
||||||
|
@ -18,3 +18,29 @@ cmd1.get('set',
|
||||||
// console.log('stdout:' + stdout)
|
// console.log('stdout:' + stdout)
|
||||||
// console.log('stderr:' + stderr)
|
// console.log('stderr:' + stderr)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
// var HttpsProxyAgent = require('https-proxy-agent')
|
||||||
|
// var proxy = 'http://user:pass@xxx.com:port'
|
||||||
|
// var agent = new HttpsProxyAgent(proxy)
|
||||||
|
// const https = require('https')
|
||||||
|
// https.get('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', (res) => {
|
||||||
|
// console.log('状态码:', res.statusCode)
|
||||||
|
// console.log('请求头:', res.headers)
|
||||||
|
//
|
||||||
|
// res.on('data', (d) => {
|
||||||
|
// process.stdout.write(d)
|
||||||
|
// })
|
||||||
|
// }).on('error', (e) => {
|
||||||
|
// console.error(e)
|
||||||
|
// })
|
||||||
|
|
||||||
|
const request = require('request')
|
||||||
|
const fs = require('fs')
|
||||||
|
request({
|
||||||
|
url: 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js',
|
||||||
|
proxy: 'http://127.0.0.1:1181',
|
||||||
|
ca: fs.readFileSync('C:/Users/Administrator/.dev-sidecar/dev-sidecar.ca.crt')
|
||||||
|
// eslint-disable-next-line handle-callback-err
|
||||||
|
}, (err, res, body) => {
|
||||||
|
console.log(body)
|
||||||
|
})
|
||||||
|
|
|
@ -28,11 +28,14 @@ class WindowsSystemProxy extends SystemProxy {
|
||||||
ret = await winExec(`npm config set https-proxy=http://${ip}:${port}`)
|
ret = await winExec(`npm config set https-proxy=http://${ip}:${port}`)
|
||||||
console.log('npm https proxy set success', ret)
|
console.log('npm https proxy set success', ret)
|
||||||
|
|
||||||
ret = await winExec(`npm config set ca ${config.getDefaultCACertPath()}`)
|
// ret = await winExec(`npm config set cafile ${config.getDefaultCACertPath()}`)
|
||||||
console.log('npm cafile set success', ret)
|
// console.log('npm cafile set success', ret)
|
||||||
|
|
||||||
// ret = await winExec('npm config set strict-ssl false')
|
ret = await winExec(`npm config set NODE_EXTRA_CA_CERTS ${config.getDefaultCACertPath()}`)
|
||||||
// console.log('npm strict-ssl false success', ret)
|
console.log('npm NODE_EXTRA_CA_CERTS set success', ret)
|
||||||
|
|
||||||
|
ret = await winExec('npm config set strict-ssl false')
|
||||||
|
console.log('npm strict-ssl false success', ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async unsetProxy () {
|
static async unsetProxy () {
|
||||||
|
@ -41,10 +44,13 @@ class WindowsSystemProxy extends SystemProxy {
|
||||||
await winExec('npm config delete https-proxy')
|
await winExec('npm config delete https-proxy')
|
||||||
console.log('npm https proxy unset success')
|
console.log('npm https proxy unset success')
|
||||||
|
|
||||||
await winExec('npm config delete ca')
|
// await winExec('npm config delete cafile')
|
||||||
console.log('npm ca unset success')
|
// console.log('npm ca unset success')
|
||||||
// await winExec(' npm config delete strict-ssl')
|
await winExec('npm config delete NODE_EXTRA_CA_CERTS')
|
||||||
// console.log('npm strict-ssl true success')
|
console.log('npm NODE_EXTRA_CA_CERTS unset success')
|
||||||
|
|
||||||
|
await winExec(' npm config delete strict-ssl')
|
||||||
|
console.log('npm strict-ssl true success')
|
||||||
}
|
}
|
||||||
|
|
||||||
static _asyncRegSet (regKey, name, type, value) {
|
static _asyncRegSet (regKey, name, type, value) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class WindowsSystemProxy extends SystemProxy {
|
||||||
ret = await winExec(`yarn config set https-proxy=http://${ip}:${port}`)
|
ret = await winExec(`yarn config set https-proxy=http://${ip}:${port}`)
|
||||||
console.log('yarn https proxy set success', ret)
|
console.log('yarn https proxy set success', ret)
|
||||||
|
|
||||||
ret = await winExec(`yarn config set ca ${config.getDefaultCACertPath()}`)
|
ret = await winExec(`yarn config set cafile ${config.getDefaultCACertPath()}`)
|
||||||
console.log('yarn cafile set success', ret)
|
console.log('yarn cafile set success', ret)
|
||||||
|
|
||||||
// ret = await winExec('yarn config set strict-ssl false')
|
// ret = await winExec('yarn config set strict-ssl false')
|
||||||
|
@ -42,7 +42,7 @@ class WindowsSystemProxy extends SystemProxy {
|
||||||
await winExec('yarn config delete https-proxy')
|
await winExec('yarn config delete https-proxy')
|
||||||
console.log('yarn https proxy unset success')
|
console.log('yarn https proxy unset success')
|
||||||
|
|
||||||
await winExec('yarn config delete ca')
|
await winExec('yarn config delete cafile')
|
||||||
console.log('yarn ca unset success')
|
console.log('yarn ca unset success')
|
||||||
|
|
||||||
// await winExec(' yarn config delete strict-ssl')
|
// await winExec(' yarn config delete strict-ssl')
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
const os = require('os')
|
||||||
|
module.exports = {
|
||||||
|
isWindows7 () {
|
||||||
|
const version = os.release()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
const os = require('os')
|
||||||
|
const util = {
|
||||||
|
getNodeVersion () {
|
||||||
|
const version = process.version
|
||||||
|
console.log(version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
util.getNodeVersion()
|
||||||
|
module.exports = util
|
|
@ -22,7 +22,6 @@ let inited = false
|
||||||
export function apiInit () {
|
export function apiInit () {
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
return doInvoke('getApiList').then(list => {
|
return doInvoke('getApiList').then(list => {
|
||||||
console.log('apiList', list)
|
|
||||||
inited = true
|
inited = true
|
||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
bindApi(item)
|
bindApi(item)
|
||||||
|
|
|
@ -108,13 +108,11 @@ export default {
|
||||||
this.proxy = this.createProxyBtns()
|
this.proxy = this.createProxyBtns()
|
||||||
this.reloadConfig().then(() => {
|
this.reloadConfig().then(() => {
|
||||||
this.start(true)
|
this.start(true)
|
||||||
console.log('proxy', this.proxy)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
reloadConfig () {
|
reloadConfig () {
|
||||||
return api.config.reload().then(ret => {
|
return api.config.reload().then(ret => {
|
||||||
console.log('config', ret)
|
|
||||||
this.config = ret
|
this.config = ret
|
||||||
return ret
|
return ret
|
||||||
})
|
})
|
||||||
|
@ -128,7 +126,6 @@ export default {
|
||||||
},
|
},
|
||||||
createProxyBtns () {
|
createProxyBtns () {
|
||||||
const btns = {}
|
const btns = {}
|
||||||
console.log('api.proxy', api.proxy, api)
|
|
||||||
for (const type in api.proxy) {
|
for (const type in api.proxy) {
|
||||||
btns[type] = {
|
btns[type] = {
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -169,7 +166,7 @@ export default {
|
||||||
this.settings.visible = true
|
this.settings.visible = true
|
||||||
},
|
},
|
||||||
onConfigChanged (newConfig) {
|
onConfigChanged (newConfig) {
|
||||||
console.log('config chagned', newConfig)
|
console.log('config changed', newConfig)
|
||||||
this.reloadConfig().then(() => {
|
this.reloadConfig().then(() => {
|
||||||
if (this.status.server) {
|
if (this.status.server) {
|
||||||
return api.server.restart()
|
return api.server.restart()
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
// const cmd1 = require('node-cmd')
|
||||||
|
// cmd1.get('set',
|
||||||
|
// function (err, data, stderr) {
|
||||||
|
// console.log('cmd complete:', err, data, stderr)
|
||||||
|
// if (err) {
|
||||||
|
// console.error('cmd 命令执行错误:', err, stderr)
|
||||||
|
// } else {
|
||||||
|
// console.log('cmd 命令执行结果:', data)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
|
||||||
|
// var process = require('child_process')
|
||||||
|
//
|
||||||
|
// var cmd = 'set'
|
||||||
|
// process.exec(cmd, function (error, stdout, stderr) {
|
||||||
|
// console.log('error:' + error)
|
||||||
|
// console.log('stdout:' + stdout)
|
||||||
|
// console.log('stderr:' + stderr)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// var HttpsProxyAgent = require('https-proxy-agent')
|
||||||
|
// var proxy = 'http://127.0.0.1:1181'
|
||||||
|
// var agent = new HttpsProxyAgent(proxy)
|
||||||
|
// console.log('111',process.env.NODE_EXTRA_CA_CERTS)
|
||||||
|
// const https = require('https')
|
||||||
|
// https_options = {
|
||||||
|
// "agent": agent,
|
||||||
|
// };
|
||||||
|
// https.get('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', https_options,(res) => {
|
||||||
|
// console.log('状态码:', res.statusCode)
|
||||||
|
// console.log('请求头:', res.headers)
|
||||||
|
//
|
||||||
|
// res.on('data', (d) => {
|
||||||
|
// process.stdout.write(d)
|
||||||
|
// })
|
||||||
|
// }).on('error', (e) => {
|
||||||
|
// console.error(e)
|
||||||
|
// })
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const content = fs.readFileSync('C:\\Users\\Administrator\\.dev-sidecar\\dev-sidecar.ca.crt')
|
||||||
|
console.log('content:',JSON.stringify(content.toString().replace(new RegExp('\r\n','g'),'\n')));
|
Loading…
Reference in New Issue