0

I have a beautiful full stack app with NodeJS on the server side and ReactJS on the client side. The app relies on Socket.IO package, both Server and Client API.

On my computer, everything works fine on localhost 4000 for node and localhost 3000 for react. Perfect communication on every socket events. But in the future, my set up will be a bit different.

I want to host the server side code on one server, called here SERVER_A, and the client side code on another server, called here SERVER_B, acting like a gateway for the users. What I would expect is a client would open http://SERVER_B:80/myapp on he's personal computer, my react app would open and all of the socket communication would be done internally between SERVER_B and SERVER_A, leaving the client with the data emitted by the node app. But what really happens is, the user on he's personal computer needs to reach both port 80 of SERVER_B and port 4000 of SERVER_A for the entire app to run properly.

This is a bummer because this type of communication should be done under the hood. Is there any way I can restrict the socket listen and emit events between Node and React and keep the client with the rendered data only?

Hope this was clear and sorry for the noobness... :)

Thanks in advance!

1
  • I'm not sure how to answer this question because it seems to me like the undesired behavior you want to avoid is a question of implementation. Which means the solution would be to "write code that actually does what you want to happen". If you need real-time communication between server A and a client of server B, you need to either open a socket connection from client B to server A, or forward the messages between client & server B to server A. Commented Sep 10, 2018 at 14:07

2 Answers 2

0

The default port a VirtualHost will respond with is configured "under the hood" (invisible to a first sight of a non-malicious consumer). So your client will see https://SERVER_B/ and https://SERVER_A but the DEFAULT port will differe.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you want to make SERVER_A something like invisible to the user.Instead under the hood it serves SERVER_B for the data. If its so I think you have to setup a virtual host in SERVER_B (use something like proxy) to communicate between SERVER_B and SERVER_A.So whenever your client makes request to the SERVER_B(for connection associated to node app)the SERVER_B will make socket connection to the SERVER_A and the communication proceeds.

If I have to say I would not recommend to do so beacause these sort of setup will degrade the performace.The reason behind this is, SERVER_B has to first read the client streams then write the streams to SERVER_A.When SERVER_A sends some streams it has to again write back to the client.

2 Comments

Yes, that's pretty much the intention here. Actually, I was hoping that SERVER_B was something like a single client for SERVER_A and the users on their personal computers were just viewing the data received by SERVER_B. But what happens is every user connected to SERVER_B acts like a different client of SERVER_A.
If thats what you want you should use something like proxy in SERVER_B. But this setup is not the best one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.