|
|
@@ -1,6 +1,7 @@
|
|
|
package com.etotem.cfc.config;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@@ -11,13 +12,17 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.*;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
@Configuration
|
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(WebConfig.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private JwtInterceptor jwtInterceptor;
|
|
|
|
|
|
@@ -33,7 +38,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|
|
@Override
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
registry.addMapping("/**")
|
|
|
- .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "http://localhost:*", "http://127.0.0.1:*")
|
|
|
+ .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "https://www.cf-club.com", "http://www.cf-club.com", "https://cfc.cf-club.com", "http://cfc.cf-club.com", "http://localhost:*", "http://127.0.0.1:*")
|
|
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
|
|
.allowedHeaders("*")
|
|
|
.allowCredentials(true)
|
|
|
@@ -48,6 +53,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|
|
@Override
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
throws IOException, ServletException {
|
|
|
+ HttpServletRequest req = (HttpServletRequest) request;
|
|
|
HttpServletResponse resp = (HttpServletResponse) response;
|
|
|
resp.setHeader("Access-Control-Allow-Private-Network", "true");
|
|
|
chain.doFilter(request, response);
|
|
|
@@ -55,6 +61,29 @@ public class WebConfig implements WebMvcConfigurer {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ /** 诊断过滤器:记录所有请求的来源和状态码 */
|
|
|
+ @Bean
|
|
|
+ @Order(Ordered.HIGHEST_PRECEDENCE + 1)
|
|
|
+ public Filter diagnosticFilter() {
|
|
|
+ return new Filter() {
|
|
|
+ @Override
|
|
|
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
+ throws IOException, ServletException {
|
|
|
+ HttpServletRequest req = (HttpServletRequest) request;
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ chain.doFilter(request, response);
|
|
|
+ int status = ((HttpServletResponse) response).getStatus();
|
|
|
+ long ms = System.currentTimeMillis() - start;
|
|
|
+ if (status == 403 || req.getRequestURI().contains("/api/payment")) {
|
|
|
+ log.warn("[DIAG] {} {} -> {} ({}ms) origin={} ua={}",
|
|
|
+ req.getMethod(), req.getRequestURI(), status, ms,
|
|
|
+ req.getHeader("Origin"),
|
|
|
+ req.getHeader("User-Agent"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
registry.addInterceptor(jwtInterceptor)
|