Search code examples
javahtmlspring-bootcross-domainspring-websocket

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


Solution

  • 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