I use Spring to write the service API. There was a need for web socket to implement progress bar and notifications. The API is spinning on port 8080 (default), and the web snout itself is respectively 80. To connect, I use SockJS and STOMP. I do everything on this tutor http://spring-projects.ru/guides/messaging-stomp-websocket/ Actually the question: how to allow clients from other domains to connect? And is it possible to limit such domains?

    1 answer 1

    See information on setting the cross-origin in the spring. Should help.

    In particular either

    @CrossOrigin(origins = "http://localhost:9000") @RequestMapping("/greeting") public String Greeting greeting() { System.out.println("==== in greeting ===="); return "wow, cross-origin string!"; } 

    or in the case of settings for the entire application

     @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/greeting-javaconfig").allowedOrigins("http://localhost:9000"); } }; } 

    More details can be found here.