Last active
May 30, 2017 00:00
-
-
Save jimallman/408dd36f6356440dea5a to your computer and use it in GitHub Desktop.
Test of Proxy Auto-Configuration (PAC) file as a replacement for messing with /etc/hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FindProxyForURL( url, host ) { | |
var debugging = false; | |
var debugPAC; | |
if (debugging) { | |
debugPAC = "host: "+ host +"\n"; | |
debugPAC += "url: "+ url +"\n"; | |
debugPAC += "dnsDomainIs(host, 'devtree.opentreeoflife.org'): "+ dnsDomainIs(host, "devtree.opentreeoflife.org") +"\n"; | |
debugPAC += "dnsDomainIs( host, '.devtree.opentreeoflife.org' ): "+ dnsDomainIs( host, '.devtree.opentreeoflife.org' ) +"\n"; | |
debugPAC += "shExpMatch(host, 'devtree.opentreeoflife.org'): "+ shExpMatch(host, "devtree.opentreeoflife.org") +"\n"; | |
} | |
if(shExpMatch(host, 'devtree.opentreeoflife.org') | |
/* OR use other options like so: | |
shExpMatch(host, "devtree.opentreeoflife.org") | |
|| dnsDomainIs( host, ".devapi.opentreeoflife.org" ) | |
|| dnsDomainIs( host, ".baz.example.com" ) | |
*/ | |
) { | |
// It's the web-app server! Proxy to the local test server instead. | |
ProxyConfig = "PROXY localhost"; | |
} | |
// Reduce volume of alerts to a useable level | |
// TODO: Filter for the main request of the tree-viewer Feedback page? | |
if (debugging && shExpMatch(host, 'devtree.opentreeoflife.org')) { // shExpMatch(url,"*/contact")) { | |
// N.B. These alerts will appear in odd places | |
// - Chrome, browse to chrome://net-internals/#events and filter for 'PAC_JAVASCRIPT_ALERT' | |
alert(debugPAC); | |
} | |
if(shExpMatch(url, "http://devtree.opentreeoflife.org/") || | |
shExpMatch(url, "https://devtree.opentreeoflife.org/")) { | |
// It's the web-app server! Proxy to the local test server instead. | |
alert("DEVTREE! using localhost proxy..."); | |
return "PROXY localhost"; | |
} | |
return "DIRECT"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment