Skip to content

Commit

Permalink
fix : Cors preflight 통과하도록 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
alsduq1117 committed Sep 6, 2023
1 parent f5003a1 commit f7e07ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/co/kr/jurumarble/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
Expand Down Expand Up @@ -47,4 +50,5 @@ public void addCorsMappings(final CorsRegistry registry) {
.allowedOrigins("http://localhost:3000","https://jurumarble-git-develop-chooz.vercel.app/","https://jurumarble.site","https://jurumarble.vercel.app/")
.maxAge(3600);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

Expand All @@ -28,6 +29,9 @@ private static Long getUserIdFromToken(HashMap<String, Object> parseJwtTokenMap)
@Override
// 컨트롤러 호출전에 호출
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (request.getMethod().equals(HttpMethod.OPTIONS.name())) { //preflight 통과하도록 설정
return true;
}
String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
parseTokenAndTransferUserId(request, authorizationHeader);
return true;
Expand All @@ -38,4 +42,5 @@ private void parseTokenAndTransferUserId(HttpServletRequest request, String auth
Long userId = getUserIdFromToken(parseJwtTokenMap);
request.setAttribute("userId", userId);
}

}

0 comments on commit f7e07ae

Please sign in to comment.