-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from hyundai-fruitfruit/HEENDY-66-CORS-FIX
[HEENDY-66-CORS-FIX] CorsConfig 수정
- Loading branch information
Showing
1 changed file
with
17 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |