I am new to web development and trying to understand how things work.
I have a Debian remote server with domain www.example.com
.
On it i have a java application running as daemon process on port 4321
.
I have also setup an apache server on the Debian remote server that serves an index.html
file which contains the Frontend of my application including the javascript code that needs to send get request to http://localhost:4321/data
to fetch data from my backend at port 4321
and render it in the html file.
I know this may seem obvious to many of you, but when calling www.example.com
from my browser (not the Debian remote server but my own local machine) i get the index.html
file displayed in my browser but all the get request methods inside the script tag fail because they are interpreting localhost
as my local computer and trying to talk with an application on port 4321
on my computer to fetch data instead of www.example.com
, which obviously does not exist.
What am i missing, and am i hosting my application the right way ?
Thanks in advance.
Assuming you also proxy requests for /data to the java application, you're hosting things the typical way.
The deviant part is the client-side javascript request explicitly trying to make requests against localhost. As you said, this can't work because it's runnin in each browser, not on the proxy server. It's a client side technology.
The only way "localhost" would work is if your proxy server (a CGI or apache module for example) or another piece of your java application were reaching out for yet more data.