feiyu02
2025-09-30 6904763f0e74d9a9fa4dbc39f635d2aee39416c6
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
30
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
 
@Deprecated("使用tomcat的web.xml配置跨域")
//@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)
    }
}