0

I have react app and nodejs api server. React app make fetch requests to nodejs server. React app and nodejs server deployed in own containers.

The problem is I can access nodejs server directly in browser, so is there way to 'hide' nodejs backend server, and let access only through frontend.

It should work something like this

  1. React app make fetch request
  2. nginx intercept request and forward to nodejs server
  3. nodejs handles request

I think it can be done with nginx reverse proxy or docker networks or somehow...

3
  • What do you hope to accomplish by doing this? No matter how many layers of indirection you add, if a React app in the user's browser can eventually access the nodejs server, then so can anything else that the user wants. Commented Oct 19, 2019 at 20:21
  • Having a single nginx that serves the built frontend application and also proxies a backend server is pretty routine. Is there a specific problem you're running into? Commented Oct 19, 2019 at 20:38
  • Something like this? stackoverflow.com/questions/32778839/… Commented Oct 19, 2019 at 21:06

1 Answer 1

1

yes there is. What you do is run a docker-compose that runs 3 docker containers. One container runs nginx, the second one runs create-react-app host ui, and the 3rd one runs a node js api. You then set the nginx routing rule for all /api/* routes to be reverse proxied to the nodejs api then you make sure all other get requests /* go to the create-react-app being hosted.

Here is a similar example on medium: https://medium.com/@xiaolishen/develop-in-docker-a-node-backend-and-a-react-front-end-talking-to-each-other-5c522156f634

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

1 Comment

This is not exactly what I wanted, but I think it’s the best I can do. Thanks.

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.