KOTLIN_CORS_ADVICE_FILE_CONTENT
private val KOTLIN_CORS_ADVICE_FILE_CONTENT: String = "
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter
/**
* The `CORSAdvice` class is useful to set the CORS policy
*
* @author N7ghtm4r3 - Tecknobit
*/
@Configuration
class CORSAdvice {
/**
* Method to set the CORS filter
*
* No any-params required
*/
@Bean
fun corsFilter(): FilterRegistrationBean<*> {
val source = UrlBasedCorsConfigurationSource()
val config = CorsConfiguration()
config.allowCredentials = false
config.addAllowedOrigin("*")
config.addAllowedHeader("*")
config.addAllowedMethod("*")
source.registerCorsConfiguration("/**", config)
val bean: FilterRegistrationBean<*> = FilterRegistrationBean(CorsFilter(source))
bean.order = 0
return bean
}
}"
KOTLIN_CORS_ADVICE_FILE_CONTENT
the
content of the CORSAdvice file, as Kotlin class, to set
the CORS origin policy for the backend