What does the backend server listens to??

when u make backend, does your server listen to your pages URL?? that is when u say host your webpage, it is hosted on a url. does the the back listen to THAT url? or the localhost of the machine that hosts the site? The little so knowledge i have about backend thus far, FR and BE communicate with eachother via API. But the question i asked above, this occurred to me when I was thinking about how when u click a link, it redirects user to a certain route.. Now there 2 possible ways that can be done as far as I can think of
We just simply use anchor tags or js with location.href to simply add that route to the Link and redirect. As user lands on that page, static elements r rendered and dynamics infos r fetched using API from the backend and later rendered. In this case i suppose the server can just listen to the machines localhost??
2ndly, server listens to the users location and based on where user is server does it's stuff..
Now idk if 2nd one is even a legit way to do it . but these r the 2 possibilities i can think of. Thanks!
6 Replies
Joao
Joao11mo ago
A web server runs and listens to connections on the computer it runs on. Using an URL is a way to identify which computer requests are sent to. You can have multiple web servers running on the same machine, one for each website, but on different ports. If you make a request for http://example.com this request will come in through port 80 on that machine. Why port 80? That's the default, but you can make a request to http://example.com:3000 for port 3000, and so on. Whether or not there's an actual web server listening on that port is another story. Typically, that's not the case. When hosting multiple sites on the same computer you typically have a web server that acts as a so-called reverse proxy. It reads incoming requests and based on the URL is can further route them to the respective destinations. What you are describing in your second option is what companies like Cloudflare and other CDNs do. They basically setup servers all over the world and replicate the content they are serving on behalf of their customers, so that the same domain is routed to their nearest physical server.
Jochem
Jochem11mo ago
to be clear, this is talking about geographical location, not location on the site. The server doesn't know what's going on in your browser URL bar until a request is submitted, either through Javascript or by the browser through a navigation
Joao
Joao11mo ago
Seems I misunderstood that second point, yeah. I thought it was asking geographical location indeed.
glutonium
glutoniumOP11mo ago
i see... i guess i am just making myself confused for no reason by overcomplicating stuff.. I think i got it.. Thank you ❤️ sorry for the late response tho ;-;
Joao
Joao11mo ago
No worries and ask away if you have questions, it can be very useful to have an understanding of how this works.
glutonium
glutoniumOP11mo ago
sure ^^
Want results from more Discord servers?
Add your server