diff --git a/api-gateway/src/main/java/kr/mafoo/gateway/config/CorsConfigurationFilter.java b/api-gateway/src/main/java/kr/mafoo/gateway/config/CorsConfigurationFilter.java deleted file mode 100644 index 2d0f1fb..0000000 --- a/api-gateway/src/main/java/kr/mafoo/gateway/config/CorsConfigurationFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -package kr.mafoo.gateway.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.web.cors.reactive.CorsUtils; -import org.springframework.web.server.WebFilter; -import reactor.core.publisher.Mono; - -@Configuration -public class CorsConfigurationFilter { - @Bean - public WebFilter corsFilter() { - return (ctx, chain) -> { - ServerHttpRequest request = ctx.getRequest(); - - if(CorsUtils.isPreFlightRequest(request)) { - ServerHttpResponse response = ctx.getResponse(); - HttpHeaders headers = response.getHeaders(); - headers.add("Access-Control-Allow-Origin", "*"); - headers.add("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS"); - headers.add("Access-Control-Max-Age", "3600"); - headers.add("Access-Control-Allow-Headers", "Authorization, Content-Type"); - headers.add("Access-Control-Allow-Credentials", "true"); - - if (request.getMethod() == HttpMethod.OPTIONS) { - response.setStatusCode(HttpStatus.OK); - return Mono.empty(); - } - } - - return chain.filter(ctx); - }; - } -} diff --git a/api-gateway/src/main/resources/application.yaml b/api-gateway/src/main/resources/application.yaml index 376409d..501b87c 100644 --- a/api-gateway/src/main/resources/application.yaml +++ b/api-gateway/src/main/resources/application.yaml @@ -3,6 +3,16 @@ spring: name: api-gateway cloud: gateway: + default-filters: + - DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials + globalcors: + add-to-simple-url-handler-mapping: true + cors-configurations: + '[/**]': + allowedOrigins: 'http://localhost:3000,https://mafoo.kr,https://dev.mafoo.kr' + allow-credentials: true + allowedHeaders: '*' + allowedMethods: '*' routes: - id: user-service uri: https://user-service.mafoo.kr