refactor: pacpath重构
parent
53f199a4a9
commit
13d34a025b
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
NODE_TLS_REJECT_UNAUTHORIZED: true,
|
||||
script: {
|
||||
enabled: true,
|
||||
defaultDir: '../../../scripts/'
|
||||
defaultDir: './extra/scripts/'
|
||||
},
|
||||
userBasePath: getUserBasePath(),
|
||||
rootCaFile: {
|
||||
|
|
|
@ -19,6 +19,6 @@ module.exports = {
|
|||
// update: [
|
||||
// 'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt'
|
||||
// ],
|
||||
customPacFilePath: './extra/pac/pac.txt'
|
||||
pacFilePath: './extra/pac/pac.txt'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,7 @@ const configJson = fs.readFileSync(configPath)
|
|||
const config = JSON5.parse(configJson)
|
||||
const scriptDir = '../../gui/extra/scripts/'
|
||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||
const pacFilePath = '../../gui/extra/pac/pac.txt'
|
||||
config.plugin.overwall.pac.customPacFilePath = path.join(__dirname, pacFilePath)
|
||||
|
||||
server.start(config)
|
||||
|
|
|
@ -6,10 +6,9 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
const configJson = fs.readFileSync(configPath)
|
||||
const config = JSON5.parse(configJson)
|
||||
let scriptDir = '../extra/scripts/'
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
scriptDir = '../extra/scripts/'
|
||||
}
|
||||
config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||
|
||||
// const scriptDir = '../extra/scripts/'
|
||||
// config.setting.script.defaultDir = path.join(__dirname, scriptDir)
|
||||
// const pacFilePath = '../extra/pac/pac.txt'
|
||||
// config.plugin.overwall.pac.customPacFilePath = path.join(__dirname, pacFilePath)
|
||||
config.setting.rootDir = path.join(__dirname, '../')
|
||||
server.start(config)
|
||||
|
|
|
@ -20,9 +20,9 @@ module.exports = {
|
|||
keys = [keys]
|
||||
}
|
||||
try {
|
||||
let tags = getScript('global', monkey.get(setting.script.defaultDir).global.script)
|
||||
let tags = getScript('global', monkey.get(setting.script.dirAbsolutePath).global.script)
|
||||
for (const key of keys) {
|
||||
const script = monkey.get(setting.script.defaultDir)[key]
|
||||
const script = monkey.get(setting.script.dirAbsolutePath)[key]
|
||||
if (script == null) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -56,8 +56,9 @@ function loadScript (content) {
|
|||
}
|
||||
|
||||
function readFile (rootDir, script) {
|
||||
log.info('script root location', path.resolve('./'))
|
||||
const location = path.join(rootDir, './' + script)
|
||||
log.debug('script location:', location)
|
||||
log.info('script location:', location)
|
||||
return fs.readFileSync(location).toString()
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = function createOverWallIntercept (overWallConfig) {
|
|||
}
|
||||
if (overWallConfig.pac) {
|
||||
// 初始化pac
|
||||
pacClient = pac.createPacClient(overWallConfig.pac.customPacFilePath)
|
||||
pacClient = pac.createPacClient(overWallConfig.pac.pacFileAbsolutePath)
|
||||
}
|
||||
|
||||
let server = overWallConfig.server
|
||||
|
|
|
@ -8,8 +8,9 @@ function createPacClient (pacFilePath) {
|
|||
|
||||
function readFile (location) {
|
||||
try {
|
||||
log.info('pac root dir', path.resolve('./'))
|
||||
const filePath = path.resolve(location)
|
||||
log.debug('read pac path:', filePath)
|
||||
log.info('read pac path:', filePath)
|
||||
return fs.readFileSync(location).toString()
|
||||
} catch (e) {
|
||||
log.error('读取pac失败')
|
||||
|
|
|
@ -2,6 +2,7 @@ const interceptors = require('./lib/interceptor')
|
|||
const dnsUtil = require('./lib/dns')
|
||||
const log = require('./utils/util.log')
|
||||
const matchUtil = require('./utils/util.match')
|
||||
const path = require('path')
|
||||
const createOverwallMiddleware = require('./lib/proxy/middleware/overwall')
|
||||
|
||||
module.exports = (config) => {
|
||||
|
@ -12,7 +13,11 @@ module.exports = (config) => {
|
|||
const serverConfig = config
|
||||
const setting = serverConfig.setting
|
||||
|
||||
const overwallMiddleware = createOverwallMiddleware(serverConfig.plugin.overwall)
|
||||
setting.script.dirAbsolutePath = path.join(setting.rootDir, setting.script.defaultDir)
|
||||
|
||||
const overwallConfig = serverConfig.plugin.overwall
|
||||
overwallConfig.pac.pacFileAbsolutePath = path.join(setting.rootDir, overwallConfig.pac.pacFilePath)
|
||||
const overwallMiddleware = createOverwallMiddleware(overwallConfig)
|
||||
const middlewares = []
|
||||
if (overwallMiddleware) {
|
||||
middlewares.push(overwallMiddleware)
|
||||
|
|
|
@ -4,7 +4,7 @@ const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
|
|||
const path = require('path')
|
||||
const filename = path.join(proxyConfig.getDefaultCABasePath(), '/logs/server.log')
|
||||
log4js.configure({
|
||||
appenders: { std: { type: 'stdout', level: 'debug' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
|
||||
appenders: { std: { type: 'stdout', level: 'debug' }, file: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
|
||||
categories: { default: { appenders: ['file', 'std'], level } }
|
||||
})
|
||||
const logger = log4js.getLogger('server')
|
||||
|
|
Loading…
Reference in New Issue