Skip to content

Commit 0cc8c03

Browse files
committed
feat(cors): webConfig, securityFilterChain 에 cors 추가
1 parent 1c5f3b8 commit 0cc8c03

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/main/java/com/somemore/global/configure/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.RequiredArgsConstructor;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.security.config.Customizer;
1112
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1213
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1314
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -37,6 +38,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
3738
.logout(AbstractHttpConfigurer::disable)
3839
.sessionManagement(sessionManagement ->
3940
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
41+
.cors(Customizer.withDefaults())
4042

4143
.authorizeHttpRequests(request ->
4244
request
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.somemore.global.configure;
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+
.allowedOrigins(
14+
"http://localhost:3000",
15+
"http://front-deploy.s3-website.ap-northeast-2.amazonaws.com"
16+
)
17+
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
18+
.allowedHeaders("*")
19+
.allowCredentials(true)
20+
.maxAge(3600);
21+
}
22+
}

0 commit comments

Comments
 (0)