Stop editing your /etc/hosts for local development.

Yuri Fenyuk
3 min readOct 4, 2022

--

I have read many times in techy articles that local computer /etc/hosts file were temporarily edited to have test domain to localhost mapping. And that seemed always was couple seconds operation. Usually, this one-time purpose modification stays in the file forever, polluting it, at a minimum.

Until recently I read this paragraph in Kubernetes Ingress documentation. As appeared, there is testing domain (maintained by Amazon) that always resolves localdev.me (and aaa.localdev.me, and zzz.localdev.me) domain to localhost (i.e. 127.0.0.1).

traceroute returns 127.0.0.1

Let’s quickly create bare backend service to simulate local development situation, when Engineer troubleshoots an important issue and just cannot find the problem using http://localhost. Scaffolded nest.js project has one more HTTP-Get handler to reveal request object details:

#5: handler function runs on /some-url URL

#8…#11: handler function return request details

The whole test project can be found here, although it is defaulted nest.js Rest API template with one modification shown above.

Let’s run this project locally on non-standard 5555 port. Using Postman to send test requests:

request on localhost

Nothing unusual, request to http://localhost:5555/some-url indeed handled with locally run backend.

Here comes the magic (dead simple and still handy):

request on localdev.me

Although the request was sent to localdev.me domain it was handled by backend server run locally! Still, it is possible to get original host localdev.me:5555 from within backend server.

The subdomain can be added to request without problem:

request on subdomain-one.localdev.me

I would agree that situations, when local development can not be carried on with localhost, are not too frequent….. still, its not a reason to amend your /etc/hosts for the sake of one troubleshooting.

After googling, a more similar ‘domain to localhost mapper’ services was found. For example, https://nip.io/.

request on my-localhost.127.0.0.1.nip.io

Make sense to read through site’s request samples list. It can resolve to any IP passed in subdomain part (not necessarily localhost but other IP can be passed). Thus, if IP 127.0.0.1 sent there, localhost backend server handles the request instead.

Even more similar sites can be found in nip.io’s Related Services section at the documentation bottom page.

request on my-nestjs-site.local.gd

For sure, there are more similar services that can be found on Internet. The important thing to remember is that such an approach exists.

--

--