manidos
manidos

Reputation: 3464

How to redirect a HTTP request to localhost on windows?

I've created a node.js app. When it runs my mobile phone can connect to it using address 192.168.1.5. In other words, when I open a browser on my phone and enter 192.168.1.5 I get a welcome page served by the app running on my PC.

The problem is that the IP address is not human friendly. Is there a way to access my app by an alias? For example, http://myapp or something like this?

Upvotes: 0

Views: 3482

Answers (1)

O. Jones
O. Jones

Reputation: 108841

Yes, these aliases are provided by the domain name service (DNS). You need to set up a hostname on DNS to point to your machine's local address.

Put that IP address into a DNS server.

Here's a free way to do that.

  • Create a FreeDNS account by visiting https://freedns.afraid.org/
  • Click on Subdomains.
  • Click the Add link.
  • Create a subdomain hostname under one of FreeDNS's public domains. Maybe mydev.manidos.mooo.com is a good choice
  • Put your machine's IP address into it. Then, use https://mydev.manidos.mooo.com to hit your development machine's nodejs app.

You can pay FreeDNS to register your own domain name and use that if you prefer.

There are all sorts of other ways to register a domain and then add address records to it, to translate from hostnames to IP addresses.

Edit If you were connecting to and from your desktop / laptop machine, you could add a hostname to your hosts file. The hosts file is itself a little DNS registry that's local to your machine. On windows it's at C:\Windows\System32\drivers\etc\hosts. On *nix and mac it's at /etc/hosts.

But, you are connecting to your app from a mobile device. Editing the hosts file in a mobile device is unreasonably difficult.

Upvotes: 1

Related Questions