In the react app I am trying to access the node-app service via reverse proxy config in the nginx.conf file as below
'server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri /index.html;
}
location /myroute1/ {
proxy_pass http://node-app:3000; # Forward API requests to the Node.js service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
’
But when I try to access the ‘/myroute1’ via a fetch call in the react app I get 404 status code. Can you please help me resolve this. I want to be able to access the node-app service and get a json response back as that too load balanced by docker itself between multiple replicas
Not sure about the error you’re experiencing, but if you’re accessing node-app internally, you may remove the ports property from that service, as it currently maps it to a random port on your host
Would you try doing the same without the network properties, so your containers use the default network Compose will create for them?
I did try after removing the networks option in yml but its still the same. When I do
docker-compose exec react-app sh
curl /node-app:3000/myroute1
I get a proper JSON response from the node server however it looks like the nginx is not resolving the request
/localhost/myroute1 to node-app:3000/myroute1 even with the proxy pass config in the conf file
Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.