DEV Community

Medam Mahesh
Medam Mahesh

Posted on

How to link Custom Domain with URL ?

Hi,
I am developing a service like Wix.com, Squarespace etc., using NodeJs
Can someone help me understand how they link custom domain name with the users website ?

Eg: A user owns a domain examplewebsite.in . Now he creates a website in Wix.com and links his domain to the website. How is the linking happening here ?

Thanks in advance

Top comments (4)

Collapse
 
richardj profile image
R☭

They do that by changing the DNS records for your domain. So you have a domain, that points to a certain ip address (A records), and you can change it to whatever you want if you own the domain name.

Basically a service like squarespace can change those records for you if you give them access to that (even easier when you buy that domain through them). And they do that however you would do that through an interface with your domain registrar.

Collapse
 
memahesh profile image
Medam Mahesh

Hi,
Can you give me more context using this example?
Suppose I own service like wix.com and I have a customer 'A' who owns a domain 'xyz.com'. Customer 'A' builds his website through my service and now he wants his website to be rendered when someone browses 'xyz.com'. How can I achieve that through a coding interface?

P.S.: I want to code it in such a way that Customer 'A' can point his website to the domain 'xyz.com' without anybody's help.

Collapse
 
richardj profile image
R☭

Well, you can't fully achieve that through a coding interface, i think. So let me draw you up how i have done it for some of my domains.

So i've built a website and that website is running on a certain with an IP. You can browse to that website by typing in the IP, and voila you see the website. But i want users to be able to visit my website through my-domain.com. A few things need to happen:

  1. We need to tell whoever owns the domain, that when a user goes to my-domain.com that we actually want to connect with a certain IP address. This is what the DNS records are for. They tell you what it should actually looking at when a user sees my-domain.com and will be something like: A record 192.168.0.1

  2. optional: When you have a single server with a lot of websites on it we need to differentiate what website we want to show the user. Because how would we know which website to serve when we point to 192.168.0.1? This is where the web server comes into place. In there you define configuration files which basically say: listen to this port, if the domain the request is coming from is my-domain.com load the following folders in the webserver.

So to go back. If you own a service like wix.com AND the user will buy their domain through you, you could do all the steps yourself programmatically (i think, there could be some caveat), if the domain name is bought with a different provider, the user needs to change the settings through their provider to point that domain name to the service (like wix.com). And in most cases the user has to put in that information themselves.

Collapse
 
prakis profile image
Kishore

Lets say you want to build a website like wix and you want to let users point their domain to your server. First you need to run a webserver (assuming the site is a static sites) you can use something like CaddyServer.com which is perfect for static sites with custom domains (even other webservers can do that like Nginx).

Now assume two users A and B want to point their domains(lets say A.com and B.com). What you need is the following..

Then you will ask your users A and B to point their domain names to A/CNAME to your server IP address. On your Caddyserver you will add these two domain names and point A.com to a local directory like /user-sites/A-com/ which will have all the static sites like index.html ...

When the DNS for A.com arrives at your server, CaddyServer will serve files from /user-sites/A-com directory.