springBoot + webSocket 报错 Origin check enabled but transport 'jsonp' does not support it.
因为我的项目是springBoot+vue的前后端分离项目,我在开发时使用proxy代理实现前后端跨域请求proxyTable: {'/': {target: 'http://localhost:8080', // 接口的域名// secure: false,// 如果是https接口,需要配置这个参数changeOrigin: tru...
·
因为我的项目是springBoot+vue的前后端分离项目,我在开发时使用proxy代理实现前后端跨域请求
proxyTable: {
'/': {
target: 'http://localhost:8080', // 接口的域名
// secure: false, // 如果是https接口,需要配置这个参数
changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
pathRewrite: {
'/': '/'
}
}
},
所以在springBoot的websocket配置文件开启sockjs时加上准许跨域setAllowedOrigins("")
The method **setAllowedOrigins("")** is used to CORS-enable the server so cross-origin clients can connect to the server. If your requirements do not need cross-origin client connection, you can remove this invocation.
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/ws/endpointChat").setAllowedOrigins("*").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue","/topic");
}
}
更多推荐
已为社区贡献6条内容
所有评论(0)