Skip to content

Commit

Permalink
Merge pull request #18 from hyundai-fruitfruit/HEENDY-66-CORS-FIX
Browse files Browse the repository at this point in the history
[HEENDY-66-CORS-FIX] CorsConfig 수정
  • Loading branch information
osy9757 authored Feb 27, 2024
2 parents 4271aba + b494361 commit cf484d4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/java/com/hyundai/app/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package com.hyundai.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* @author 황수영
* @since 2024/02/10
* CORS 설정
*/
/**
* @author 엄상은
* @since 2024/02/26
* CORS 설정 에러 해결
*/
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
public class CorsConfig implements WebMvcConfigurer {
private final long MAX_AGE_SECS = 3600;

source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(MAX_AGE_SECS);
}
}

0 comments on commit cf484d4

Please sign in to comment.