|
@@ -4,8 +4,6 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
|
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
@@ -14,9 +12,6 @@ import java.time.format.DateTimeFormatter;
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
- @Value("${cors.allowed-origins:}")
|
|
|
|
|
- private String corsAllowedOrigins;
|
|
|
|
|
-
|
|
|
|
|
@Bean
|
|
@Bean
|
|
|
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
|
|
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
|
|
|
return builder -> builder.serializers(
|
|
return builder -> builder.serializers(
|
|
@@ -25,13 +20,8 @@ public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
- // 未配置 CORS 来源时,默认只允许本地开发地址,生产请通过 CORS_ALLOWED_ORIGINS 注入
|
|
|
|
|
- String origins = StringUtils.hasText(this.corsAllowedOrigins)
|
|
|
|
|
- ? this.corsAllowedOrigins
|
|
|
|
|
- : "http://localhost:3000,http://127.0.0.1:3000";
|
|
|
|
|
- String[] originArray = origins.split(",");
|
|
|
|
|
registry.addMapping("/**")
|
|
registry.addMapping("/**")
|
|
|
- .allowedOriginPatterns(originArray)
|
|
|
|
|
|
|
+ .allowedOriginPatterns("*")
|
|
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|
|
.allowedHeaders("*")
|
|
.allowedHeaders("*")
|
|
|
.allowCredentials(true)
|
|
.allowCredentials(true)
|