道路线索应急巡查系统服务后台
feiyu02
2025-09-30 84569abda51ecf6c5549dec4cadee8d043422379
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
31
32
33
package com.flightfeather.grid.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 {
            addAllowedOriginPattern("http://localhost:*")
            addAllowedOriginPattern("http://47.100.191.150:*")
            addAllowedOriginPattern("http://fyami.com.cn:*")
            addAllowedOriginPattern("http://192.168.*.*:*")
//            addAllowedOrigin("*")
            addAllowedHeader("*")
            addAllowedMethod("*")
            allowCredentials = true
        }
    }
 
//    @Bean
    fun corsFilter(): CorsFilter {
        val source = UrlBasedCorsConfigurationSource().apply {
            registerCorsConfiguration("/**", buildConfig())
        }
 
        return CorsFilter(source)
    }
}