gaurav kumar
gaurav kumar

Reputation: 129

Cross Domain WebSocket Connection [Spring Boot]

I have two instances of spring boot services running. let's say 'app1:8080' and another instance 'app2:7070'. Where as 'app1:8080' is hosting a html page , which tries to connect a web-socket connection with 'app2:7070', whenever it get launched. Something like this : var webSocket = new WebSocket("ws://app2:7070/socket-endpoint");

But i am always getting 403 error message. I have read about the cross-domain and have tried to register the 'app1:8080' in 'app2:7070'. But couldn't find any solution.

Server technology : spring boot client technology : HTML5

Upvotes: 0

Views: 1314

Answers (1)

Jonathan Lechner
Jonathan Lechner

Reputation: 581

Most probably this results from cross origin calls. You have different options to solve this:

  • put a load balancer like nginx in front of both applications and serve them with the same base URL
  • serve the html from the same application (the easiest solution if its a small application)
  • or allow cross origin calls in app2 from app1 in your case, like documented here

Upvotes: 1

Related Questions