23 May 2013

localhost subdomains

I maintain a multitenant rails application where each customer (tenant) gets its own subdomain.

In order to develop and test this application on my development computer I use the domain lvh.me which uses a DNS trick, this domains and all its subdomains point to localhost.

This way I can type customer1.lvh.me:3000 and it just works. No need to touch anything on your computer.

Today I receive a bug report that only happens on IE < 10 (oh well!). I usually just use a Windows machine and type my dev machine IP on the address bar, however this time I need to access a subdomain on my dev machine so 192.168.1.XXX:3000 was not going to work.

The solution was to edit the file \Windows\system32\drivers\etc\hosts and add the following entry:

192.168.1.100   myapp.com

This way now I can type http://customer1.myapp.com:3000 on the Windows machine and get it routed to my dev box with the subdomain name.