1- //// GatewayConfig.java
2- // package com.joketdan.gateway.config;
3- //
4- // import org.springframework.context.annotation.Bean;
5- // import org.springframework.context.annotation.Configuration;
6- // import org.springframework.core.annotation.Order;
7- // import org.springframework.web.cors.CorsConfiguration;
8- // import org.springframework.web.cors.reactive.CorsWebFilter;
9- // import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
10- //
11- // import java.util.List;
12- //
13- // @Configuration
14- // public class GatewayConfig {
15- //
16- // @Bean
17- // @Order(-1) // ⚠️ CORS 필터가 가장 먼저 실행되도록 (0보다 작은 값)
18- // public CorsWebFilter corsWebFilter() {
19- // CorsConfiguration config = new CorsConfiguration();
20- //
21- // // ✅ setAllowedOrigins 대신 setAllowedOriginPatterns 사용
22- // config.setAllowedOriginPatterns(List.of(
23- // "http://localhost:5173",
24- // "http://localhost:*", // 개발 환경용
25- // "https://yourdomain.com" // 프로덕션 도메인 추가
26- // ));
27- //
28- // config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
29- // config.setAllowedHeaders(List.of("*"));
30- // config.setAllowCredentials(true);
31- //
32- // // ✅ 응답 헤더 노출 (프론트엔드에서 읽을 수 있도록)
33- // config.setExposedHeaders(List.of(
34- // "Authorization",
35- // "X-User-Id",
36- // "X-User-Roles",
37- // "X-User-Email",
38- // "Set-Cookie"
39- // ));
40- //
41- // // ✅ Preflight 캐시 시간 (초 단위)
42- // config.setMaxAge(3600L);
43- //
44- // UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
45- // source.registerCorsConfiguration("/**", config);
46- // System.out.println("CORS Configuration loaded: " + config);
47- //
48- // return new CorsWebFilter(source);
49- //
50- // }}
1+ // GatewayConfig.java
2+ package com .joketdan .gateway .config ;
3+
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .Configuration ;
6+ import org .springframework .core .annotation .Order ;
7+ import org .springframework .web .cors .CorsConfiguration ;
8+ import org .springframework .web .cors .reactive .CorsWebFilter ;
9+ import org .springframework .web .cors .reactive .UrlBasedCorsConfigurationSource ;
10+
11+ import java .util .List ;
12+
13+ @ Configuration
14+ public class GatewayConfig {
15+
16+ @ Bean
17+ @ Order (-1 ) // ⚠️ CORS 필터가 가장 먼저 실행되도록 (0보다 작은 값)
18+ public CorsWebFilter corsWebFilter () {
19+ CorsConfiguration config = new CorsConfiguration ();
20+
21+ // ✅ setAllowedOrigins 대신 setAllowedOriginPatterns 사용
22+ config .setAllowedOriginPatterns (List .of (
23+ "http://localhost:5173" ,
24+ "http://localhost:*" , // 개발 환경용
25+ "https://yourdomain.com" // 프로덕션 도메인 추가
26+ ));
27+
28+ config .setAllowedMethods (List .of ("GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" , "PATCH" ));
29+ config .setAllowedHeaders (List .of ("*" ));
30+ config .setAllowCredentials (true );
31+
32+ // ✅ 응답 헤더 노출 (프론트엔드에서 읽을 수 있도록)
33+ config .setExposedHeaders (List .of (
34+ "Authorization" ,
35+ "X-User-Id" ,
36+ "X-User-Roles" ,
37+ "X-User-Email" ,
38+ "Set-Cookie"
39+ ));
40+
41+ // ✅ Preflight 캐시 시간 (초 단위)
42+ config .setMaxAge (3600L );
43+
44+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
45+ source .registerCorsConfiguration ("/**" , config );
46+ System .out .println ("CORS Configuration loaded: " + config );
47+
48+ return new CorsWebFilter (source );
49+
50+ }}
0 commit comments