From 6033bd25feba863338a5c7a5003b4ec80f929a3e Mon Sep 17 00:00:00 2001 From: pjhcsols Date: Mon, 4 Nov 2024 19:51:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:[kakao-tech-campus-2nd-step3#28]=20WebSock?= =?UTF-8?q?etConfig=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ .../global/config/WebSocketConfig.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/com/helpmeCookies/global/config/WebSocketConfig.java 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