How to use local domains for development
Published 2018-07-01
I tend to work on a whole bunch of services at once, and I can never keep track of all the ports I'm using - was my server running on localhost:8150 or on localhost:8500?
Wouldn't it be great if I could use a domain name for local dev, maybe something like goatcodes.wip or frontend.wip instead?
Editing /etc/hosts
doesn't quite work because I'd still have to remember the port. I could setup a local DNS server to resolve those URLs, but that has the same problem. Plus configuring DNS servers is a deep old magic beyond my ken.
hotel is popular solution to this exact problem, but it requires node and wants to be installed globally, something I'm allergic to.
So I wrote a simple service to do just that: lightproxy.
lightproxy lets you map hostnames to a local port. You can also point a hostname to a folder and serves file directly out of the folder, ala python -m SimpleHTTPServer
.
If you have Homebrew, you can install lightproxy with:
$ brew install octavore/tools/lightproxy
Once you have it, it's a few easy steps to get going:
- Add domains from the command-line, e.g.:
lightproxy set-dest frontend.wip localhost:8150
- Start the server:
lightproxy start
- Configure your proxy settings to use http://localhost:7999/proxy.pac as its automatic configuration URL (instructions for MacOS, Ubuntu).
PS. Fun fact - I used to use .dev
domains, as did many others, but Google purchased that TLD and so it doesn't work very well nowadays. .localhost
is what hotel recommends. I prefer .wip
myself because development is by definition "work in progress". It's also six characters shorter. It isn't as future-proof because someone may register it in the future, but that's a problem for another day.