I was recently at lunch showing off a project to one of our clients. I don’t often think about internet access before I go anywhere — these days I just assume I’ll always have internet. Unfortunately, however, this particular restaurant didn’t have public WiFi. Well, that shouldn’t be a problem — I’m showing the app locally anyway.
I got to the restaurant, opened my laptop, tried to access app.dev and bam — I got the sad “no internet connection” error page. I thought for a second. I could boot up the server on my machine; localhost will be available. But wait, if localhost is available, shouldn’t my .dev domains? They’re not real domains! But your computer thinks they are. That’s why it tries to connect to the internet. But with one simple line in your hosts file (/etc/hosts on a Mac) you can easily convince your computer that they’re not. Just add the following after the localhost declarations:
That’ll make sure that your computer routes all requests for app.dev to your local machine. Somewhat inconveniently, the hosts file doesn’t accept wildcard characters, so you’ll have to add entries for each of your apps.