Sub-domains and Developer Testing

Sometimes you sell accounts to your web application with unique sub-domain per license. This is a neat way of handling accounts and gives you lot control.

For e.g. lets say you have built hotel-reservations-engine in Ruby on Rails and are planning to license it for many different hotels. The best way to do that would be use sub-domains to your advantage. There are many blog posts that tells you how to achieve this on Ruby On Rails and the production server.

My focus is though, how to get this working in your developer machine without any dilly-dally of hosts file.

Use Name Server To Your Advantage:

For e.g. lets say you manage your DNS records with tinydns which has a great feature of wild-card alias, and you add the following entries…

+local.example.com:127.0.0.1
+*.local.example.com:127.0.0.1

after propagation its all yours:

local.example.com => 127.0.0.1
sub1.local.example.com => 127.0.0.1
sub2.local.example.com => 127.0.0.1
sub3.local.example.com => 127.0.0.1

Note the * in the +*.local.example.com:127.0.0.1 which does the trick.

No more editing the hosts file, and it works for all developers pointing to their own machine. Nice!

Leave a Comment