Shortly after my post on setting up wildcard DNS on localhost domains on OSX, there was a much-needed breakthrough in the realm of ruby localhost development. Sam Stephenson introduced Pow, which aims to simplify the running of multiple development apps on localhost.
Rather than manually run standalone webservers (ugh), or add entries to an nginx+passenger config file (less ugh), with Pow you can simply symlink your myproject directory into
~/.pow and then hit
http://myproject.dev and things will just work.
How’s this work? Well, Pow is a node app running on localhost which has two functions:
- Serving rack apps
- Serving DNS requests
When you symlink a project directory into
~/.pow, you’re telling Pow that a Rack app lives there. Pow listens on
localhost:80 for http requests, and based on the hostname requested, serves the appropriate Rack app.
Pow uses an interesting trick to get the
*.dev URLs resolving to localhost: on installation it adds the file
/etc/resolver/dev which on OSX acts as a DNS resolution config for the
.dev domain. It instructs your computer to use the namserver at
127.0.0.1:20560 to resolve any domain with the TLD of
.dev. The Pow server binds to that port and serves DNS for
.dev domain requests — it resolves all hostnames to
Pow also supports RVM and Bundler, so you can simultaneously run projects with different ruby versions and gemsets, a feat not currently possible with nginx+passenger without adding upstream proxying to standalone Passenger instances.
Overall a very welcome contribution to the ruby developer community. I’ll be sticking with nginx+passenger for now as I require some special nginx modules for a few projects, but the next time a designer needs to get up and running on a project, it’ll be much easier to get this done. I might even be able to do it without having to take over the keyboard.