Commit 553193e9 authored by saliou673's avatar saliou673
Browse files

fix cors issue

parent dd7df08d
.idea/
webapp/yarn.lock
package com.example.server.config.websocket;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {
/**
* Add CORS mapping.
* @param registry registry
*/
@Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:4200", "http://127.0.0.1:4200");
}
}
......@@ -20,7 +20,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry
.addEndpoint("/gkz-stomp-endpoint")
.setAllowedOrigins("http://localhost:4200")
.setAllowedOrigins("http://127.0.0.1:4200")
.withSockJS();
}
}
......@@ -27,7 +27,7 @@ export class AppComponent {
}
connect() {
const socket = new SockJS('http://localhost:8080/gkz-stomp-endpoint');
const socket = new SockJS('http://localhost:8000/gkz-stomp-endpoint');
// @ts-ignore
this.stompClient = Stomp.over(socket);
......@@ -38,8 +38,8 @@ export class AppComponent {
console.log('Connected: ' + frame);
// @ts-ignore
_this.stompClient.subscribe('/api/hi', function (hello){
_this.showGreeting(JSON.parse(hello.body).greeting);
_this.stompClient.subscribe('/api/hi', function (response){
_this.showGreeting(JSON.parse(response.body));
});
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment