|
@@ -1,5 +1,6 @@
|
|
|
package com.bowintek.smartsearch.config;
|
|
|
|
|
|
+import com.bowintek.smartsearch.filter.HostHeaderInterceptor;
|
|
|
import com.bowintek.smartsearch.filter.TokenInterceptor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -19,6 +20,9 @@ public class WebConfiguration implements WebMvcConfigurer {
|
|
|
@Autowired
|
|
|
private TokenInterceptor tokenInterceptor;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private HostHeaderInterceptor hostHeaderInterceptor;
|
|
|
+
|
|
|
/**
|
|
|
* 解决跨域请求
|
|
|
* @param registry
|
|
@@ -26,11 +30,11 @@ public class WebConfiguration implements WebMvcConfigurer {
|
|
|
@Override
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
registry.addMapping("/**")
|
|
|
- .allowedHeaders("*")
|
|
|
- .allowedMethods("*")
|
|
|
-// .allowedOrigins("*")
|
|
|
- .allowedOriginPatterns("*")
|
|
|
- .allowCredentials(true);
|
|
|
+ .allowedOrigins("http://localhost:8077","http://10.73.178.222:8077/")
|
|
|
+ .allowedMethods("GET", "POST") // 允许的 HTTP 方法
|
|
|
+ .allowedHeaders("Content-Type", "Authorization") // 允许的请求头
|
|
|
+ .allowCredentials(true) // 允许携带凭据(如 cookies)
|
|
|
+ .maxAge(3600); // 预检请求的缓存时间
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -70,7 +74,9 @@ public class WebConfiguration implements WebMvcConfigurer {
|
|
|
registry.addInterceptor(tokenInterceptor)
|
|
|
.addPathPatterns("/**")
|
|
|
.excludePathPatterns(excludePath);
|
|
|
- WebMvcConfigurer.super.addInterceptors(registry);
|
|
|
|
|
|
+ registry.addInterceptor(hostHeaderInterceptor)
|
|
|
+ .addPathPatterns("/**");
|
|
|
+ WebMvcConfigurer.super.addInterceptors(registry);
|
|
|
}
|
|
|
}
|