daangn-daangn / daangn-server

🥕당근 서버 리포지토리🥕
4 stars 2 forks source link

feat: CORS 설정 변경(3001, 3002 포트 개방) #108

Closed cotchan closed 2 years ago

cotchan commented 2 years ago

작업 내용

3000번 포트 닫고, 3001번, 3002번 포트 개방(blue, green) 하도록 CorsConfigurationSource 빈 설정 수정

import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

@Bean
public CorsConfigurationSource configurationSource() {
    List<String> clientUrls = List.of("http://localhost:3001", "http://localhost:3002");

    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setAllowedOrigins(clientUrls);
    configuration.addAllowedHeader("*");
    configuration.addAllowedMethod("*");
    configuration.setAllowCredentials(true);
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

    source.registerCorsConfiguration("/**", configuration);
    return source;
}