mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
3.1.3
This commit is contained in:
@@ -3,10 +3,10 @@ package com.gitee.sop.gatewaycommon.manager;
|
|||||||
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
||||||
import com.gitee.sop.gatewaycommon.bean.ApiContext;
|
import com.gitee.sop.gatewaycommon.bean.ApiContext;
|
||||||
import com.gitee.sop.gatewaycommon.bean.BeanInitializer;
|
import com.gitee.sop.gatewaycommon.bean.BeanInitializer;
|
||||||
import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor;
|
|
||||||
import com.gitee.sop.gatewaycommon.bean.SpringContext;
|
import com.gitee.sop.gatewaycommon.bean.SpringContext;
|
||||||
import com.gitee.sop.gatewaycommon.gateway.loadbalancer.NacosServerIntrospector;
|
import com.gitee.sop.gatewaycommon.gateway.loadbalancer.NacosServerIntrospector;
|
||||||
import com.gitee.sop.gatewaycommon.interceptor.MonitorRouteInterceptor;
|
import com.gitee.sop.gatewaycommon.interceptor.MonitorRouteInterceptor;
|
||||||
|
import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor;
|
||||||
import com.gitee.sop.gatewaycommon.limit.LimitManager;
|
import com.gitee.sop.gatewaycommon.limit.LimitManager;
|
||||||
import com.gitee.sop.gatewaycommon.loadbalancer.SopPropertiesFactory;
|
import com.gitee.sop.gatewaycommon.loadbalancer.SopPropertiesFactory;
|
||||||
import com.gitee.sop.gatewaycommon.message.ErrorFactory;
|
import com.gitee.sop.gatewaycommon.message.ErrorFactory;
|
||||||
@@ -40,6 +40,7 @@ import org.springframework.context.event.EventListener;
|
|||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||||
import org.springframework.web.filter.CorsFilter;
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@@ -184,11 +185,35 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 跨域过滤器
|
* 跨域过滤器,zuul
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty("zuul.servlet-path")
|
||||||
public CorsFilter corsFilter() {
|
public CorsFilter corsFilter() {
|
||||||
return createCorsFilter();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", createCorsConfiguration());
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跨域过滤器,gateway
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty("sop.gateway-index-path")
|
||||||
|
public CorsWebFilter corsFilterReact() {
|
||||||
|
org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", createCorsConfiguration());
|
||||||
|
return new CorsWebFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CorsConfiguration createCorsConfiguration() {
|
||||||
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||||
|
corsConfiguration.addAllowedOrigin("*");
|
||||||
|
corsConfiguration.addAllowedHeader("*");
|
||||||
|
corsConfiguration.addAllowedMethod("*");
|
||||||
|
return corsConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,24 +236,6 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati
|
|||||||
return new EurekaServerIntrospector();
|
return new EurekaServerIntrospector();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CorsFilter createCorsFilter() {
|
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
||||||
this.registerCorsConfiguration(source);
|
|
||||||
return new CorsFilter(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerCorsConfiguration(UrlBasedCorsConfigurationSource source) {
|
|
||||||
source.registerCorsConfiguration("/**", corsConfiguration());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CorsConfiguration corsConfiguration() {
|
|
||||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
||||||
corsConfiguration.addAllowedOrigin("*");
|
|
||||||
corsConfiguration.addAllowedHeader("*");
|
|
||||||
corsConfiguration.addAllowedMethod("*");
|
|
||||||
return corsConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
this.isStartupCompleted = true;
|
this.isStartupCompleted = true;
|
||||||
|
Reference in New Issue
Block a user