Riku
2024-09-28 bda3bf8923acb5216f6f46b5d903cac24c842143
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cn.flightfeather.supervision.config
 
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
 
@Configuration
class CorsConfig {
 
    private fun buildConfig(): CorsConfiguration {
        return CorsConfiguration().apply {
            addAllowedOrigin("*")
            addAllowedHeader("*")
            addAllowedMethod("*")
            allowCredentials = true
        }
    }
 
    @Bean
    fun corsFilter(): CorsFilter {
        val source = UrlBasedCorsConfigurationSource().apply {
            registerCorsConfiguration("/**", buildConfig())
        }
 
        return CorsFilter(source)
    }
}