|
@@ -6,6 +6,7 @@ import org.springframework.web.servlet.config.annotation.CorsRegistration;
|
6
|
6
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
7
|
7
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
8
|
8
|
|
|
9
|
+import javax.servlet.http.HttpServletRequest;
|
9
|
10
|
import java.util.List;
|
10
|
11
|
|
11
|
12
|
@SpringBootConfiguration
|
|
@@ -14,6 +15,9 @@ public class CorsConfig implements WebMvcConfigurer {
|
14
|
15
|
@Autowired
|
15
|
16
|
CorsProperties crosProperties;
|
16
|
17
|
|
|
18
|
+ @Autowired
|
|
19
|
+ HttpServletRequest request;
|
|
20
|
+
|
17
|
21
|
@Override
|
18
|
22
|
public void addCorsMappings(CorsRegistry registry) {
|
19
|
23
|
if (null == crosProperties.getEnabled() || !crosProperties.getEnabled()) return;
|
|
@@ -23,9 +27,10 @@ public class CorsConfig implements WebMvcConfigurer {
|
23
|
27
|
//是否发送Cookie
|
24
|
28
|
// registration.allowCredentials(true);
|
25
|
29
|
// 域名
|
26
|
|
- registration.allowedOrigins(toArray(crosProperties.getOrigins()));
|
|
30
|
+ String origin = request.getHeader("Origin");
|
|
31
|
+ registration.allowedOrigins(origin);
|
27
|
32
|
//放行哪些请求方式
|
28
|
|
- registration.allowedMethods(toArray(crosProperties.getMethods()));
|
|
33
|
+ registration.allowedMethods("*");
|
29
|
34
|
//放行哪些原始请求头部信息
|
30
|
35
|
registration.allowedHeaders("*");
|
31
|
36
|
//暴露哪些原始请求头部信息
|