[WEB] 📚 악명 높은 CORS 개념 & 해결법 - 정리 끝판왕 👏

Spring Cloud Gateway CORS 문제 해결하기

CORS는 왜 이렇게 우리를 힘들게 하는걸까?

추가 (In Spring Security)

Sori

<aside> 🗃️ 통과된 배포파일들

통과 배포.zip

</aside>

cors문제로 개고생을 했다. 기존에 고쳤다가 다시 발생해서.. 설정정보를 저장하고 관련 정보를 기록할려함. 사실 이게 msa구조가 아니고, gateway를 통과하는 플로우가 아니면 뚝-딱 해결했을텐데 api gateway를 거쳐서 가는 구조라 더 빡빡했던 거 같다.

Spring Cloud Gateway yml


spring:
  application:
    name: gateway-service
  main:
    web-application-type: reactive

  cloud:
    gateway:

      default-filters:
        - DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials
      globalcors:
        cors-configurations:
          '[/**]':
            allowedOrigins: '<https://ottogi-ottogi.vercel.app>'
            allow-credentials: true
            allowedHeaders: '*'
            allowedMethods:
              - PUT
              - GET
              - POST
              - DELETE
              - OPTIONS
      routes:
        - id: user-service
          uri: lb://USER-SERVICE
          predicates:
            - Path=/user/member/**
          filters:
            - CustomAuthFilter
        - id: user-service
          uri: lb://USER-SERVICE
          predicates:
            - Path=/user/auth/**

클라우드 부분만 올렸다. allowedOrigins에는 배포된 프론트 서버를 작성해주었다.

User Service