Skip to content

Commit

Permalink
Merge pull request #19 from potenday-project/develop
Browse files Browse the repository at this point in the history
header, cookie 허용
  • Loading branch information
HwangHoYoon authored Dec 14, 2023
2 parents 36abd9f + f99ea93 commit a5c0e17
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/main/java/com/chwipoClova/common/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.chwipoClova.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.List;

@Configuration
public class CorsConfig {

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();

config.setAllowCredentials(true);
config.setAllowedOrigins(List.of("http://localhost:3000"));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
config.setAllowedHeaders(List.of("*"));
config.setExposedHeaders(List.of("*"));

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}

}
2 changes: 0 additions & 2 deletions src/main/java/com/chwipoClova/common/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
"[REQUEST] {} - {} {} - {}\n" +
"Headers : {}\n" +
"Request : {}\n" +
"Headers : {}\n" +
//"Headers : {}\n" +
"Response : {}\n",
((HttpServletRequest) customRequestWrapper).getMethod(),
((HttpServletRequest) customRequestWrapper).getRequestURI(),
responseWrapper.getStatus(),
(end - start) / 1000.0,
getHeaders(customRequestWrapper),
buildAccessLog(customRequestWrapper),
getHeaders(responseWrapper),
//getHeaders(responseWrapper),
getResponseBody(responseWrapper));
} else {
log.info("[REQUEST] {} - {} {} - {}", ((HttpServletRequest) customRequestWrapper).getMethod(), ((HttpServletRequest) customRequestWrapper).getRequestURI(), responseWrapper.getStatus(), (end - start) / 1000.0);
Expand Down

0 comments on commit a5c0e17

Please sign in to comment.