-
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.
- Loading branch information
1 parent
f16cfae
commit d0a0384
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/healthylife/config/CorsConfig.java
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.healthylife.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; | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
|
||
@Bean | ||
public CorsFilter corsFilter() { | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
CorsConfiguration config = new CorsConfiguration(); | ||
|
||
// 허용할 Origin 설정 | ||
config.addAllowedOrigin("http://ec2-43-201-150-178.ap-northeast-2.compute.amazonaws.com:8081/"); | ||
config.addAllowedOrigin("http://localhost:8081/swagger-ui/index.html"); | ||
|
||
// 모든 HTTP 메서드 허용 | ||
config.addAllowedMethod("*"); | ||
|
||
// 모든 헤더 허용 | ||
config.addAllowedHeader("*"); | ||
|
||
// 자격 증명 허용 | ||
config.setAllowCredentials(true); | ||
|
||
// 모든 경로에 대해 위의 CORS 설정 적용 | ||
source.registerCorsConfiguration("/**", config); | ||
|
||
// CORS 필터 반환 | ||
return new CorsFilter(source); | ||
} | ||
} |
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