|
|
@@ -1,33 +1,17 @@
|
|
|
package com.qqflow.engine.config;
|
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
@Configuration
|
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
- @Value("${cors.allowed-origins:http://localhost:3000,http://127.0.0.1:3000}")
|
|
|
- private String allowedOrigins;
|
|
|
-
|
|
|
@Override
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
- List<String> origins = Arrays.stream(allowedOrigins.split(","))
|
|
|
- .filter(StringUtils::hasText)
|
|
|
- .map(String::trim)
|
|
|
- .toList();
|
|
|
- String[] originArray = origins.isEmpty()
|
|
|
- ? new String[]{"http://localhost:3000", "http://127.0.0.1:3000"}
|
|
|
- : origins.toArray(new String[0]);
|
|
|
-
|
|
|
registry.addMapping("/**")
|
|
|
- .allowedOriginPatterns(originArray)
|
|
|
+ .allowedOriginPatterns("*")
|
|
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|
|
.allowedHeaders("*")
|
|
|
.allowCredentials(true)
|