CORS : Cross-Origin Resource Sharing(교차 출처 리소스 공유)

브라우저에서 보내는 XMLHttpRequest, Fetch API는 Same-Origin Policy(SOP)라는 보안 정책이 적용.

⇒ 브라우저에서 보안을 목적으로, Cross-Origin에 HTTP 요청을 제한하는 정책.

문제 및 원인

문제 : 인증된 사용자만 사용할 수 있는 API 요청시, CORS 문제 발생.

원인

해결

Preflight 요청이 들어왔을 때, 바로 통과시켜줄 수 있도록 수정.

 AuthInterceptor.class

private final List<String> allowedMethod = List.of("OPTIONS");

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// Option메서드로 들어온 요청은 바로 처리될 수 있도록 처리.
		if (allowedMethod.contains(request.getMethod())) {
			return true;
		}
		// 토큰 체크 과정
	}