Skip to content

Commit

Permalink
update pac (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
biuuu authored Jul 1, 2018
1 parent feaa3e9 commit 099003b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blhxfy",
"version": "0.6.2",
"version": "0.6.3",
"description": "碧蓝幻想微风机翻团",
"main": "main.js",
"scripts": {
Expand Down
25 changes: 20 additions & 5 deletions proxy/pac.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const ip = require('ip')

const someHostList = [
'www.google.com',
'*.google.com',
'*.twitter.com',
'twitter.com',
'csp.withgoogle.com',
'www.gstatic.com'
'*.google-analytics.com',
'www.gstatic.com',
'dmm.com',
'*.dmm.com'
]

const gameExtraHostList = [
'cdn-connect.mobage.jp',
'cdn-widget.mobage.jp',
'connect.mobage.jp',
'platform.twitter.com'
]

const localIp = ip.address()
Expand All @@ -18,20 +30,23 @@ module.exports = function ({ apiHostNames, staticHostNames, staticServer, frontA
const condition3 = someHostList.map(name => {
return `shExpMatch(host, "${name}")`
}).join('||')
const condition4 = gameExtraHostList.map(name => {
return `shExpMatch(host, "${name}")`
}).join('||')

const getScript = (condition) => (conditionEx) => (result) => {
const template = `
function FindProxyForURL(url, host) {
if (isInNet(dnsResolve(host),"127.0.0.1","255.255.255.0")) {
return "DIRECT";
}
if (shExpMatch(host, "${localIp}")) {
if (shExpMatch(host, "${localIp}") || isPlainHostName(host)) {
return "DIRECT";
}
if (${condition} || ${conditionEx}) {
return "PROXY ${localIp}:${port};DIRECT";
}
if (${frontAgent} && (${condition2})) {
if (${frontAgent} && (${condition2} || ${condition4} || ${condition3})) {
return "PROXY ${localIp}:${frontAgentPort}; PROXY 127.0.0.1:${frontAgentPort}; DIRECT"
}
if (!${frontAgent} && (${condition3})) {
Expand All @@ -50,7 +65,7 @@ module.exports = function ({ apiHostNames, staticHostNames, staticServer, frontA
script = script('false')
}
if (frontAgent) {
script = script(`PROXY ${localIp}:${frontAgentPort}; PROXY 127.0.0.1:${frontAgentPort}; DIRECT`)
script = script(`DIRECT; PROXY ${localIp}:${frontAgentPort}; PROXY 127.0.0.1:${frontAgentPort}`)
} else {
script = script(`DIRECT; PROXY ${localIp}:${frontAgentPort}; PROXY 127.0.0.1:${frontAgentPort}`)
}
Expand Down

0 comments on commit 099003b

Please sign in to comment.