简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM