Book-Microservices-v2 / chapter08d

Learn Microservices with Spring Boot (2nd edition) - Chapter 8 (FINAL)
https://tpd.io/book-extra
11 stars 18 forks source link

in Docker, how challenge-frontend connect to gateway? #4

Open EricWangZ opened 2 years ago

EricWangZ commented 2 years ago

I used Docker-Compose bring up the system. but when I play with the browser and find it does not work.

the whole system is running in one server, say: 10.10.10.10; my browser is runing in my laptop, say 10.10.10.11

the browser cannot get any response from multiplication or gamification service, only can connect to challenge-frontend.

I use Chrome Developer Tool, found the request sent from the frontend is "http://localhost:8000/challenges/random". I am wondering if this localhost can work. I guess this local host still referring to my laptop, not the server running the application.

I am not sure if my understanding is correct or not.

mechero commented 2 years ago

Hi! You're right, there are some defaults in the code and one of the assumptions is that you run the frontend and the backend in the same address, and Docker can map localhost to the container server (ports are mapped to the host). If you use different addresses or your Docker environment runs on a VM for example, then you can change the code to point to the proper server or even make it configurable.