I tried to override the default configuration of the spring websocket plugin for Grails, like this :
@Configuration
@EnableWebSocketMessageBroker
class CorsWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
void configureMessageBroker(MessageBrokerRegistry messageBrokerRegistry) {
messageBrokerRegistry.enableSimpleBroker "/queue", "/topic"
messageBrokerRegistry.setApplicationDestinationPrefixes "/app"
}
@Override
void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
StompWebSocketEndpointRegistration registration = stompEndpointRegistry.addEndpoint("/stomp")
registration.setAllowedOrigins('http://localhost', 'http://localhost:8080')
registration.withSockJS().setSupressCors(false)
}
// [...]
}
I also tried by doing a .setAllowedOrigins('*'), but it still won't work.
However, when I register my client, the "Access-Control-Allow-Origin" header is never set on the /stomp/info endpoint. I always get "XMLHttpRequest cannot load http://localhost:8080/app/stomp/info. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access."
i pushed a grails-3.0.2/grails-spring-websocket-2.0.0 sample app to https://github.com/zyro23/so-30891198 which shows that it should be working.
and the second sample using grails-2.5.0/spring-websocket-1.3.0: https://github.com/zyro23/so-30891198-2