DEV Community

Hidayt Rahman
Hidayt Rahman

Posted on

7

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 :)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay