로컬에서 프론트와 백엔드 테스트를 진행하면 꼭 cors 설정을 해줘야한다.
도메인이 같고 포트만 다르기 때문에 정책상 에러가 난다.
cors정책과 관련된 자세한 내용은 아래 참고한 url을 써놓을게요!
https://xiubindev.tistory.com/115
나를 너무나 힘들게 했던 CORS 에러 해결하기 😂
🔥 사건의 발단 : 외부 API 호출 때는 바야흐로 2020년 3월. 프론트엔드 공부를 시작한 지 얼마 되지 않은 채 홀로 토이 프로젝트를 진행하던 중이었다. 코로나 바이러스 관련 웹서비스를 만들고자
xiubindev.tistory.com
에러 내용
When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
해결스프링 버전이 올라가면서 .allowedCredentials(true) 와 .allowedOrigins("*") 를 동시에 사용할 수 없도록 변경되었다고 한다. (나는 v4.0.0).allowedOrigin("*")를 .allowedOriginPattern("*") 로 변경해서 전역을 허용하거나, corsFilter에 addAllowedOrigin을 전역이 아닌 허용할 도메인을 적어주면 오류 해결!
config.addAllowedOrigin("http://localhost:3000");
'BACKEND > error' 카테고리의 다른 글
개발자 공급 과잉과 경기 침체 속에서 취업하기(feat.현재 상황 error 404) (1) | 2025.04.06 |
---|---|
javax.net.ssl.SSLHandshakeException: General SSLEngine problem (0) | 2022.11.08 |
빈 생성 에러 Consider defining a bean of type~ (0) | 2022.08.12 |
IntelliJ cannot resolve symbol.. 에러 해결 (0) | 2021.12.09 |