Skip to content

Commit

Permalink
cors enable (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored Feb 27, 2024
1 parent cf0c140 commit be1336a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions common/src/main/kotlin/com/fone/common/config/CorsFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fone.common.config

import org.springframework.context.annotation.Bean
import org.springframework.http.HttpMethod
import org.springframework.stereotype.Component
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.reactive.CorsWebFilter
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource

@Component
class CorsFilter {
@Bean
fun corsWebFilter(): CorsWebFilter {
val corsConfig = CorsConfiguration()
corsConfig.addAllowedOrigin("*")
corsConfig.maxAge = 8000L
corsConfig.addAllowedMethod(HttpMethod.GET)
corsConfig.addAllowedMethod(HttpMethod.POST)
corsConfig.addAllowedMethod(HttpMethod.OPTIONS)
corsConfig.addAllowedHeader("Content-Type")

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

return CorsWebFilter(source)
}
}

0 comments on commit be1336a

Please sign in to comment.