Procházet zdrojové kódy

fix: 移除全局 CORS 拦截器,避免与网关重复添加 CORS 头

- 网关层(K8s Ingress/Tengine)已给所有响应添加 Access-Control-Allow-Origin: *
- 后端 CrosDomainAllowInterceptor 又添加一次,导致浏览器收到重复头被拦截
- 移除拦截器注册,让网关统一处理 CORS

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
刘立冬 před 1 týdnem
rodič
revize
4078c22d88

+ 5 - 9
server/src/main/java/com/tzld/videoVector/Application.java

@@ -1,6 +1,5 @@
 package com.tzld.videoVector;
 
-import com.tzld.videoVector.interceptor.CrosDomainAllowInterceptor;
 import org.mybatis.spring.annotation.MapperScan;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -9,15 +8,17 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
+/**
+ * CORS 由 K8s Ingress / 阿里云 Tengine 网关统一处理,后端不再重复加 CORS 头,
+ * 否则浏览器会因 Access-Control-Allow-Origin 出现多个值而拦截响应。
+ */
 @SpringBootApplication
 @MapperScan("com.tzld.videoVector.dao")
 @ServletComponentScan("com.tzld.videoVector.controller")
 @EnableDiscoveryClient
 @EnableFeignClients
-public class Application implements WebMvcConfigurer {
+public class Application {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
 
@@ -25,9 +26,4 @@ public class Application implements WebMvcConfigurer {
         SpringApplication.run(Application.class, args);
         LOGGER.info("video-vector-server Start Success");
     }
-
-    @Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        registry.addInterceptor(new CrosDomainAllowInterceptor()).addPathPatterns("/**");
-    }
 }