Skip to content

Commit 3879f87

Browse files
JIWONKIMSclaude
andcommitted
fix(websocket): Add explicit HTTPS origin for WebSocket CORS
- Add setAllowedOrigins() to explicitly allow HTTPS connections - Fixes Mixed Content error when connecting from HTTPS frontend - Allow https://www.team11.giwon11292.com (production) - Allow http://localhost:3000 (development) - Add detailed STOMP connection logging for debugging Resolves: 'Cannot connect to server' WebSocket error (code 1002) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 828f9e4 commit 3879f87

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/stomp/UserChatRabbitWebSocketConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class UserChatRabbitWebSocketConfig(
2727
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
2828
registry.addEndpoint("/ws/userchat")
2929
.setAllowedOriginPatterns("*")
30+
.setAllowedOrigins("https://www.team11.giwon11292.com", "http://localhost:3000")
3031
.withSockJS()
3132
}
3233

src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/stomp/UserChatSimpleWebSocketConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class UserChatSimpleWebSocketConfig(
1717
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
1818
registry.addEndpoint("/ws/userchat")
1919
.setAllowedOriginPatterns("*")
20+
.setAllowedOrigins("https://www.team11.giwon11292.com", "http://localhost:3000")
2021
.withSockJS()
2122
}
2223

src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/stomp/UserChatStompAuthChannelInterceptor.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.back.koreaTravelGuide.domain.userChat.stomp
22

3+
import com.back.koreaTravelGuide.common.logging.log
34
import com.back.koreaTravelGuide.common.security.JwtTokenProvider
45
import org.springframework.messaging.Message
56
import org.springframework.messaging.MessageChannel
@@ -20,6 +21,8 @@ class UserChatStompAuthChannelInterceptor(
2021
): Message<*>? {
2122
val accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor::class.java) ?: return message
2223

24+
log.info("📨 [STOMP] Command: ${accessor.command}, User: ${accessor.user}, SessionId: ${accessor.sessionId}")
25+
2326
if (accessor.command == StompCommand.CONNECT) {
2427
val rawHeader =
2528
accessor.getFirstNativeHeader("Authorization")
@@ -29,7 +32,9 @@ class UserChatStompAuthChannelInterceptor(
2932
throw AuthenticationCredentialsNotFoundException("Invalid JWT token")
3033
}
3134
accessor.user = jwtTokenProvider.getAuthentication(token)
35+
log.info("✅ [STOMP] CONNECT authenticated: userId=${accessor.user?.name}")
3236
} else if (accessor.user == null) {
37+
log.error("❌ [STOMP] Unauthenticated ${accessor.command} request - SessionId: ${accessor.sessionId}")
3338
throw AuthenticationCredentialsNotFoundException("Unauthenticated STOMP request")
3439
}
3540

0 commit comments

Comments
 (0)