Locally testing apps that let users create their own subdomains can be a pain. As much as I wish it were as easy as putting "*" in /etc/hosts as a wildcard, it has to be more complicated. For a long time I had a DNS server running locally that resolved everything under .dev to 127.0.0.1, but when I replaced my hard drive recently I went shopping for a better solution. I found one, proxy auto config files.
With a little help from stack overflow I came up with the following to make anything that ends in .dev route to localhost:
function FindProxyForURL(url, host) {
if (shExpMatch(host,"*.dev")) {
var port = url.match(/^\w{3,5}:\/\/[^:\/]*(:(\d+))?/)[2];
var proxy = "PROXY localhost";
if(port){proxy += ":" + port;}
return proxy;
}
return "DIRECT";
}
Put the above in a file somewhere (I named mine ~/.proxy.pac) then to add it go to
Network in
System Prefences and add it to
Proxies in advanced mode:
This will work for Safari. You can add it again in the Firefox proxies setting, but even better is to just install the
System Proxy extension that will make Firefox use the system wide proxy settings. For IE testing in VMWare I just replaced "localhost" in the
var proxy = "PROXY localhost"; line with the IP of my mac that VMWare shares with the IE VM. IE also seemed to deal better with a pac file accessible via an HTTP URL instead of a file path so I hosted the IE pac file on my local webserver.