Skip to content

Commit e80d453

Browse files
authored
Merge pull request #55 from Project-BookLog/fix/cors
fix: cor 오류 해결
2 parents 3dcd982 + 8d1a4fd commit e80d453

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

booklog/src/main/java/com/example/booklog/aws/s3/AmazonS3Manager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import com.example.booklog.global.config.AmazonConfig;
1010
import lombok.RequiredArgsConstructor;
1111
import lombok.extern.slf4j.Slf4j;
12+
import org.springframework.context.annotation.Profile;
1213
import org.springframework.stereotype.Component;
1314
import org.springframework.web.multipart.MultipartFile;
1415

1516
import java.io.IOException;
1617

1718
@Slf4j
19+
@Profile("!local")
1820
@Component
1921
@RequiredArgsConstructor
2022
public class AmazonS3Manager {

booklog/src/main/java/com/example/booklog/global/config/AmazonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.context.annotation.Configuration;
1313
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.context.annotation.Profile;
1415

16+
@Profile("!local")
1517
@Configuration
1618
@Getter
1719
public class AmazonConfig {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.example.booklog.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6+
7+
@Configuration
8+
public class WebConfig implements WebMvcConfigurer {
9+
10+
@Override
11+
public void addCorsMappings(CorsRegistry registry) {
12+
registry.addMapping("/**")
13+
// 로컬 개발 환경 전부 커버
14+
.allowedOriginPatterns(
15+
"http://localhost:*",
16+
"http://127.0.0.1:*"
17+
)
18+
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
19+
.allowedHeaders("*")
20+
.allowCredentials(true);
21+
}
22+
}

0 commit comments

Comments
 (0)