mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-18 19:54:26 +00:00
fix: 把原生 WS 与 SockJS 分路径,避免混淆
This commit is contained in:
@@ -105,7 +105,7 @@ public class SecurityConfig {
|
|||||||
.exceptionHandling(eh -> eh.accessDeniedHandler(customAccessDeniedHandler))
|
.exceptionHandling(eh -> eh.accessDeniedHandler(customAccessDeniedHandler))
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||||
.requestMatchers("/api/ws/**").permitAll()
|
.requestMatchers("/api/ws/**", "/api/sockjs/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.POST, "/api/auth/**").permitAll()
|
.requestMatchers(HttpMethod.POST, "/api/auth/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/api/posts/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/api/posts/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/api/comments/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/api/comments/**").permitAll()
|
||||||
|
|||||||
@@ -41,23 +41,38 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
// ① 原生 WebSocket 端点:用 patterns,抗 www/端口漂移
|
// 1) 原生 WebSocket(不带 SockJS)
|
||||||
registry.addEndpoint("/api/ws")
|
registry.addEndpoint("/api/ws")
|
||||||
.setAllowedOriginPatterns(
|
.setAllowedOriginPatterns(
|
||||||
// 本地
|
|
||||||
"http://localhost:*",
|
|
||||||
"http://127.0.0.1:*",
|
|
||||||
"http://192.168.7.98:*",
|
|
||||||
"http://30.211.97.238:*",
|
|
||||||
// 线上
|
|
||||||
"https://staging.open-isle.com",
|
"https://staging.open-isle.com",
|
||||||
"https://www.staging.open-isle.com",
|
"https://www.staging.open-isle.com",
|
||||||
websiteUrl,
|
websiteUrl,
|
||||||
websiteUrl.replace("://www.", "://")
|
websiteUrl.replace("://www.", "://"),
|
||||||
).withSockJS().setWebSocketEnabled(true).setSessionCookieNeeded(false);
|
"http://localhost:*",
|
||||||
|
"http://127.0.0.1:*",
|
||||||
|
"http://192.168.7.98:*",
|
||||||
|
"http://30.211.97.238:*"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2) SockJS 回退:单独路径
|
||||||
|
registry.addEndpoint("/api/sockjs")
|
||||||
|
.setAllowedOriginPatterns(
|
||||||
|
"https://staging.open-isle.com",
|
||||||
|
"https://www.staging.open-isle.com",
|
||||||
|
websiteUrl,
|
||||||
|
websiteUrl.replace("://www.", "://"),
|
||||||
|
"http://localhost:*",
|
||||||
|
"http://127.0.0.1:*",
|
||||||
|
"http://192.168.7.98:*",
|
||||||
|
"http://30.211.97.238:*"
|
||||||
|
)
|
||||||
|
.withSockJS()
|
||||||
|
.setWebSocketEnabled(true)
|
||||||
|
.setSessionCookieNeeded(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureClientInboundChannel(ChannelRegistration registration) {
|
public void configureClientInboundChannel(ChannelRegistration registration) {
|
||||||
registration.interceptors(new ChannelInterceptor() {
|
registration.interceptors(new ChannelInterceptor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user