Home > Mobile >  Communication issue between Angular application and spring boot API deployed in a Docker container
Communication issue between Angular application and spring boot API deployed in a Docker container

Time:10-08

I’m creating an application using angular for the frontend and spring boot for the backend. Evrything works well on my local machine. But for deployment, I choose to containerize each of them in separate Docker containers. The problem came into place when I tried to call the backend api form the angular application (displayed on my browser). When I try to call the path {http://backend-address/login}, i get this error in my browser console {http://frontend-address/backend-address/login 405 (Not Allowed)}. It seems like, when I try to call the backend, the URL is always transformed, adding {frontend-address/} between http:// and the backend-address

My Docker engine is on a Linux virtual machine on the address 192.168.30.4. The spring boot container is mapped to the port 8081 of the virtual machine and the angular container is mapped to the port 4300. So, to call the spring boot API from the angular application (which is displayed on my browser), this is the request I did:

`this.httpClient.post<Tokens>("192.168.30.4:8081/login", user, {observe: "response"}).subscribe({…})`

And I got this error in my browser console:

POST http://192.168.30.4:4300/192.168.30.4:8081/login 405 (Not Allowed)

I don't anderstand why the frontend address (192.168.30.4:4300/) is inserted between the http:// and the backend address (192.168.30.4:8081)

CodePudding user response:

Try adding scheme http:// in httpClient.post "http:// 192.168.30.4:8081/login"

  • Related