Skip to content

How to enable Cors? #902

Answered by smyrick
bolanosdev asked this question in Q&A
Oct 13, 2020 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

You should be able to create a CorsWebFilter bean and that should be picked up by Spring automatically

https://enable-cors.org/server.html

@Bean
fun corsWebFilter(): CorsWebFilter {

    // Example of some basic config
    val corsConfig = CorsConfiguration()
    corsConfig.allowedOrigins = mutableListOf("https://example.com")
    corsConfig.allowedMethods = mutableListOf("GET", "POST")
    corsConfig.allowedHeaders = mutableListOf("Origin", "X-Requested-With", "Content-Type", "Accept")
    corsConfig.allowCredentials = true
    corsConfig.maxAge = 8000L

    // Set the URL matching
    val urlSource = UrlBasedCorsConfigurationSource()
    urlSource.registerCorsConfiguration("/**", corsCo…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@bolanosdev
Comment options

@smyrick
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by smyrick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants