|
@@ -3,6 +3,8 @@ package com.gis.common.config;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
|
+import com.gis.common.constant.ConfigConstant;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -19,16 +21,24 @@ import java.util.List;
|
|
|
@Configuration
|
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ConfigConstant configConstant;
|
|
|
+
|
|
|
/**
|
|
|
* 配置全局跨域
|
|
|
+ * 开发、测试环境开启跨域, 正式环境不开启
|
|
|
*/
|
|
|
@Override
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
- registry.addMapping("/**")
|
|
|
- .allowedOrigins("*")
|
|
|
- .allowCredentials(true)
|
|
|
- .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
|
|
|
- .maxAge(3600);
|
|
|
+ String active = configConstant.active;
|
|
|
+ if ("dev".equals(active) || "sit".equals(active)){
|
|
|
+ registry.addMapping("/**")
|
|
|
+ .allowedOrigins("*")
|
|
|
+ .allowCredentials(true)
|
|
|
+ .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
|
|
|
+ .maxAge(3600);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|