Quickshiftin - Clever Crazy Code

Local Development for Mobile Devices

August 10th, 2013

DNS Solutions

Ever heard of DNS? This is what you’re emulating in the first place by creating entries in /etc/hosts to begin with. All you need to get your mobile device to find your local machine is an appropriate DNS entry. Let’s take a look at how to do this.

The hacky way

So you’re at some corporate office that doesn’t have or refuses to edit DNS entries for you on their office / corporate server. It’s ugly, but a sure fire way to circumvent this issue is to create a record on a public DNS server you have access to. Yes, you heard me correctly, you can enter local addresses in a public DNS server. All DNS does is resolve IP addresses based on name. So if your local machine has an address of 192.168.56.28, and you have mydomain.com registered with GoDaddy just create an entry like local-dev.mydomain.com pointed to 192.168.56.28. Then obviously configure the site or API you’re working on to operate under the name dev.mydomain.com. Point your phone’s browser (or the API client in the native app you’re working on) to said domain and viola, you’re developing locally for mobile!

Limitations

Even though this is a clever solution there are some limitations. Obviously local addresses in a public DNS server isn’t pretty, but it’s not the end of the world either. The other issue, which will likely be more prevalent is the fact that you probably don’t have a static IP on the local network for you local machine. This means you may have to periodically change the entry in the DNS server which can be annoying. Probably not as annoying as messing with the proxy every time you want to code though! Take a look at the next solution for another approach that solves both these issues.

The elegant way

The absolute best way to deal with local dev for mobile in my book is have a local DNS server. I know some readers probably just passed out with fear or screamed in disgust but it’s really not that difficult. It comes down to buying a half-way decent router. I’ve been using a MikroTik router and it works great. If you’re on a budget, you can get the most basic model for $40.

This solution addresses all the issues that came up in the hacky way above.

  • No local addresses on a public DNS server
  • You can create static IP addresses for you local machine (easily)

And of course you’ll never have to mess with configuration every time you work on the site now. It’s always ready to go!

Share

If you enjoyed this post please consider sharing it!

  • Twitter
  • LinkedIn
  • Facebook
  • Reddit
  • Digg

Leave a Response