diff --git a/build.gradle b/build.gradle index a8dbafa..9eae86d 100644 --- a/build.gradle +++ b/build.gradle @@ -77,6 +77,9 @@ dependencies { testImplementation 'org.testcontainers:junit-jupiter:1.20.2' testImplementation 'org.testcontainers:mysql:1.20.2' + //chat + implementation 'org.springframework.boot:spring-boot-starter-websocket' + } tasks.named('test') { diff --git a/src/main/java/com/helpmeCookies/global/config/WebSocketConfig.java b/src/main/java/com/helpmeCookies/global/config/WebSocketConfig.java new file mode 100644 index 0000000..d8254c2 --- /dev/null +++ b/src/main/java/com/helpmeCookies/global/config/WebSocketConfig.java @@ -0,0 +1,23 @@ +package com.helpmeCookies.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; + +@Configuration +@EnableWebSocketMessageBroker +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + @Override + public void configureMessageBroker(MessageBrokerRegistry config) { + config.enableSimpleBroker("/api/sub"); + config.setApplicationDestinationPrefixes("/api/pub"); + } + + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + registry.addEndpoint("/ws").setAllowedOriginPatterns("*"); + //.withSockJS(); + } +} \ No newline at end of file