Skip to content

Commit e2d783f

Browse files
committed
origins in ws
1 parent 2f87a11 commit e2d783f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

backend/src/main/java/com/rk/postguard/config/SecurityConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@EnableWebSecurity
2424
@RequiredArgsConstructor
2525
public class SecurityConfig {
26-
@Value("${spring.cors.allowed-origins}")
26+
@Value("${CORS_ALLOWED_ORIGINS}")
2727
private List<String> allowedOrigins;
2828

2929

@@ -37,7 +37,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, CorsConfigurat
3737
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
3838
.authorizeHttpRequests(auth -> auth
3939
.requestMatchers("/api/v1/auth/**","/api/v1/users/**","/api/v1/analytics/**","/ping","/health","/actuator/**" ,"/ws/**").permitAll()
40-
// .requestMatchers(HttpMethod.DELETE, ).authenticated()
4140
.anyRequest().authenticated()
4241
)
4342
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

backend/src/main/java/com/rk/postguard/config/WebSocketConfig.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
import com.rk.postguard.Interceptors.WebSocketAuthInterceptor;
44
import lombok.RequiredArgsConstructor;
5+
import org.springframework.beans.factory.annotation.Value;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.messaging.simp.config.ChannelRegistration;
78
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
89
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
910
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
1011
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
1112

13+
import java.util.List;
14+
1215
@Configuration
1316
@EnableWebSocketMessageBroker
1417
@RequiredArgsConstructor
1518
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
1619
private final WebSocketAuthInterceptor webSocketAuthInterceptor;
17-
20+
@Value("${WS_ALLOWED_ORIGINS}")
21+
private List<String> allowedOrigins;
1822
@Override
1923
public void configureMessageBroker(MessageBrokerRegistry config){
2024
config.enableSimpleBroker("/topic", "/queue");
@@ -24,7 +28,7 @@ public void configureMessageBroker(MessageBrokerRegistry config){
2428
@Override
2529
public void registerStompEndpoints(StompEndpointRegistry registry) {
2630
registry.addEndpoint("/ws")
27-
.setAllowedOrigins("http://localhost:3000", "http://localhost:5173")
31+
.setAllowedOrigins(String.valueOf(allowedOrigins))
2832
.withSockJS();
2933

3034
}

0 commit comments

Comments
 (0)