DEV Community

Hidayt Rahman
Hidayt Rahman

Posted on

Serve localhost with custom domain

We are going to use your preferred custom domain in local instead of the dull localhost URL on our local system.

How?

For this example, I am using the domain name webtechpie.io, but you can use your own.

Open the hosts file in your machine.

For Window:
To update the hosts file in Windows, you can follow these steps:

  • Press the Windows key
  • Type Notepad in the search field
  • In the search results, right-click Notepad and select Run as - administrator
  • Open the hosts file at C:\Windows\System32\Drivers\etc\hosts
  • Make the necessary changes to the file
  • Select File > Save to save your changes

For Mac:
Open terminal and run the command below

$ sudo nano /private/etc/hosts
Enter fullscreen mode Exit fullscreen mode

And update the hosts file, replace the domain name with your domain.

Example

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       webtechpie.io
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

# This entry was appended by Docker Desktop because `localhost` did not resolve
# to a list of addresses which included 127.0.0.1. This can happen due to a bug
# in the macOS migration assistant, or possibly because another tool has
# corrupted the file.
127.0.0.1       localhost
Enter fullscreen mode Exit fullscreen mode

Save the file and restart the machine.

Try to access the localhost app by your domain, in my case it will be webtechpie.io

Do not forget to add the port :PORT
http://YOUR_DOMAIN:PORT

http://webtechpie.io:8080
Enter fullscreen mode Exit fullscreen mode

It should start running the app with the custom domain.

Happy.Coding :)

Top comments (0)