Skip to content

Commit 9d5da80

Browse files
authored
Merge pull request #102 from prgrms-web-devcourse-final-project/feat/be/101
feat(be): cors설정 추가
2 parents 63bd077 + c07cd7d commit 9d5da80

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main/kotlin/com/back/koreaTravelGuide/common/security/SecurityConfig.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import org.springframework.security.config.annotation.web.invoke
1111
import org.springframework.security.config.http.SessionCreationPolicy
1212
import org.springframework.security.web.SecurityFilterChain
1313
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
14+
import org.springframework.web.cors.CorsConfiguration
15+
import org.springframework.web.cors.CorsConfigurationSource
16+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
1417

1518
@Configuration
1619
class SecurityConfig(
@@ -27,6 +30,7 @@ class SecurityConfig(
2730

2831
http {
2932
csrf { disable() }
33+
cors { }
3034
formLogin { disable() }
3135
httpBasic { disable() }
3236
logout { disable() }
@@ -78,4 +82,25 @@ class SecurityConfig(
7882

7983
return http.build()
8084
}
85+
86+
@Bean
87+
fun corsConfigurationSource(): CorsConfigurationSource {
88+
return UrlBasedCorsConfigurationSource().apply {
89+
registerCorsConfiguration(
90+
"/**",
91+
CorsConfiguration().apply {
92+
allowedOriginPatterns =
93+
listOf(
94+
"http://localhost:3000",
95+
"http://localhost:63342",
96+
// 배포주소
97+
)
98+
allowedMethods = listOf("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
99+
allowedHeaders = listOf("*")
100+
allowCredentials = true
101+
maxAge = 3600
102+
},
103+
)
104+
}
105+
}
81106
}

0 commit comments

Comments
 (0)