refactor: pacpath重构

pull/88/head
xiaojunnuo 2021-08-11 14:53:43 +08:00
parent 53f199a4a9
commit 13d34a025b
10 changed files with 24 additions and 15 deletions

View File

@ -23,7 +23,7 @@ module.exports = {
NODE_TLS_REJECT_UNAUTHORIZED: true, NODE_TLS_REJECT_UNAUTHORIZED: true,
script: { script: {
enabled: true, enabled: true,
defaultDir: '../../../scripts/' defaultDir: './extra/scripts/'
}, },
userBasePath: getUserBasePath(), userBasePath: getUserBasePath(),
rootCaFile: { rootCaFile: {

View File

@ -19,6 +19,6 @@ module.exports = {
// update: [ // update: [
// 'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt' // 'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt'
// ], // ],
customPacFilePath: './extra/pac/pac.txt' pacFilePath: './extra/pac/pac.txt'
} }
} }

View File

@ -13,4 +13,7 @@ const configJson = fs.readFileSync(configPath)
const config = JSON5.parse(configJson) const config = JSON5.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)
const pacFilePath = '../../gui/extra/pac/pac.txt'
config.plugin.overwall.pac.customPacFilePath = path.join(__dirname, pacFilePath)
server.start(config) server.start(config)

View File

@ -6,10 +6,9 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const configJson = fs.readFileSync(configPath) const configJson = fs.readFileSync(configPath)
const config = JSON5.parse(configJson) const config = JSON5.parse(configJson)
let scriptDir = '../extra/scripts/' // const scriptDir = '../extra/scripts/'
if (process.env.NODE_ENV === 'development') { // config.setting.script.defaultDir = path.join(__dirname, scriptDir)
scriptDir = '../extra/scripts/' // const pacFilePath = '../extra/pac/pac.txt'
} // config.plugin.overwall.pac.customPacFilePath = path.join(__dirname, pacFilePath)
config.setting.script.defaultDir = path.join(__dirname, scriptDir) config.setting.rootDir = path.join(__dirname, '../')
server.start(config) server.start(config)

View File

@ -20,9 +20,9 @@ module.exports = {
keys = [keys] keys = [keys]
} }
try { 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) { for (const key of keys) {
const script = monkey.get(setting.script.defaultDir)[key] const script = monkey.get(setting.script.dirAbsolutePath)[key]
if (script == null) { if (script == null) {
continue continue
} }

View File

@ -56,8 +56,9 @@ function loadScript (content) {
} }
function readFile (rootDir, script) { function readFile (rootDir, script) {
log.info('script root location', path.resolve('./'))
const location = path.join(rootDir, './' + script) const location = path.join(rootDir, './' + script)
log.debug('script location:', location) log.info('script location:', location)
return fs.readFileSync(location).toString() return fs.readFileSync(location).toString()
} }

View File

@ -21,7 +21,7 @@ module.exports = function createOverWallIntercept (overWallConfig) {
} }
if (overWallConfig.pac) { if (overWallConfig.pac) {
// 初始化pac // 初始化pac
pacClient = pac.createPacClient(overWallConfig.pac.customPacFilePath) pacClient = pac.createPacClient(overWallConfig.pac.pacFileAbsolutePath)
} }
let server = overWallConfig.server let server = overWallConfig.server

View File

@ -8,8 +8,9 @@ function createPacClient (pacFilePath) {
function readFile (location) { function readFile (location) {
try { try {
log.info('pac root dir', path.resolve('./'))
const filePath = path.resolve(location) const filePath = path.resolve(location)
log.debug('read pac path:', filePath) log.info('read pac path:', filePath)
return fs.readFileSync(location).toString() return fs.readFileSync(location).toString()
} catch (e) { } catch (e) {
log.error('读取pac失败') log.error('读取pac失败')

View File

@ -2,6 +2,7 @@ const interceptors = require('./lib/interceptor')
const dnsUtil = require('./lib/dns') const dnsUtil = require('./lib/dns')
const log = require('./utils/util.log') const log = require('./utils/util.log')
const matchUtil = require('./utils/util.match') const matchUtil = require('./utils/util.match')
const path = require('path')
const createOverwallMiddleware = require('./lib/proxy/middleware/overwall') const createOverwallMiddleware = require('./lib/proxy/middleware/overwall')
module.exports = (config) => { module.exports = (config) => {
@ -12,7 +13,11 @@ module.exports = (config) => {
const serverConfig = config const serverConfig = config
const setting = serverConfig.setting 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 = [] const middlewares = []
if (overwallMiddleware) { if (overwallMiddleware) {
middlewares.push(overwallMiddleware) middlewares.push(overwallMiddleware)

View File

@ -4,7 +4,7 @@ const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
const path = require('path') const path = require('path')
const filename = path.join(proxyConfig.getDefaultCABasePath(), '/logs/server.log') const filename = path.join(proxyConfig.getDefaultCABasePath(), '/logs/server.log')
log4js.configure({ 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 } } categories: { default: { appenders: ['file', 'std'], level } }
}) })
const logger = log4js.getLogger('server') const logger = log4js.getLogger('server')