Reputation: 179
I have a public accessible web page hosted by Apache. I also have a private node server running on the side which handles get requests. It is kinda like an API.
For example if I do curl http://localhost:8080/list_of_users
, this node server will return me a json file which contains all the information.
I used jQuery in my java-script to get the json file from that nodeserver. I have http://localhost:8080/list_of_users
hard coded in it. When I was testing it locally, everything works fine. But when I try to access my webpage from other network, the page itself works but it cannot complete the get request.
I feel like I should make the node server public in order to fix the problem? But the thing is, I do not really need the node server to be accessible by everyone. I just need it to be accessible by a java-script stored on the same machine. So is there a easier way to do this rather than make the node server public?
I did googled how to make a public node server, most tutorial says I need to do a router port forwarding. I don't think I have the permission to do that... That's another reason why I am trying to find an alternative way to fix it...
I am new to this area, so I might be misunderstanding things. I apologies for any confusion my question may have caused and I appreciate all your helps.
Upvotes: 0
Views: 35
Reputation: 707976
If the Javascript that is going to access the node.js server is going to be in a webpage and executed from the user's browser, then the node.js server HAS to be publicly reachable. The Javsacript is run from the user's browser so it can only reach public things.
It does not matter that your page is stored on your Apache server in a place that can reach your private node.js server. That's not where the Javascript is run from. The page is downloaded by the user's browser and then the Javscript in the page runs in the user's browser.
So, if you keep the same page architecture, you will have to make the node.js server public and give it a public IP address/domain name.
Or, it's possible you could proxy the node.js server through your Apache server such that you make a request (probably on a specific port) to your Apache server and that request is proxied by the Apache server to your node.js server.
Upvotes: 1