|
@@ -2,8 +2,10 @@ package com.ruoyi.framework.config;
|
|
|
|
|
|
import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
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;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
@@ -19,6 +21,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
public class ResourcesConfig implements WebMvcConfigurer {
|
|
|
@Autowired
|
|
|
private RepeatSubmitInterceptor repeatSubmitInterceptor;
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
|
|
|
@Override
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
@@ -38,17 +42,19 @@ public class ResourcesConfig implements WebMvcConfigurer {
|
|
|
@Bean
|
|
|
public CorsFilter corsFilter() {
|
|
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
- /*CorsConfiguration config = new CorsConfiguration();
|
|
|
- config.setAllowCredentials(true);
|
|
|
- // 设置访问源地址
|
|
|
- config.addAllowedOrigin("*");
|
|
|
+ if ("dev".equals(env)) {
|
|
|
+ CorsConfiguration config = new CorsConfiguration();
|
|
|
+ config.setAllowCredentials(true);
|
|
|
+ // 设置访问源地址
|
|
|
+ config.addAllowedOrigin("*");
|
|
|
// config.addAllowedOriginPattern("*");
|
|
|
- // 设置访问源请求头
|
|
|
- config.addAllowedHeader("*");
|
|
|
- // 设置访问源请求方法
|
|
|
- config.addAllowedMethod("*");
|
|
|
- // 对接口配置跨域设置
|
|
|
- source.registerCorsConfiguration("/**", config);*/
|
|
|
+ // 设置访问源请求头
|
|
|
+ config.addAllowedHeader("*");
|
|
|
+ // 设置访问源请求方法
|
|
|
+ config.addAllowedMethod("*");
|
|
|
+ // 对接口配置跨域设置
|
|
|
+ source.registerCorsConfiguration("/**", config);
|
|
|
+ }
|
|
|
return new CorsFilter(source);
|
|
|
}
|
|
|
|