Skip to content

Commit

Permalink
Merge pull request #79 from wafflestudio/hotfix/cors
Browse files Browse the repository at this point in the history
Cors: Local cors
  • Loading branch information
moonpiderman authored Apr 4, 2022
2 parents baef3f7 + dd5d830 commit 7f85c6e
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource
import org.springframework.web.cors.UrlBasedCorsConfigurationSource

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
Expand All @@ -42,6 +45,21 @@ class SecurityConfig(
return provider
}

@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val corsConfiguration = CorsConfiguration()

corsConfiguration.addAllowedOrigin("http://localhost:3000")
corsConfiguration.addAllowedHeader("*")
corsConfiguration.addAllowedMethod("*")
corsConfiguration.allowCredentials = true

val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", corsConfiguration)

return source
}

override fun configure(http: HttpSecurity) {
http
.csrf().disable()
Expand Down

0 comments on commit 7f85c6e

Please sign in to comment.