|
|
@@ -1,12 +1,7 @@
|
|
|
package com.sckw.freight.config;
|
|
|
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.web.cors.CorsConfiguration;
|
|
|
-import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
-import org.springframework.web.filter.CorsFilter;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
/**
|
|
|
* @BelongsProject: Freight-Settlement-Backend
|
|
|
* @BelongsPackage: com.sckw.freight.config
|
|
|
@@ -14,18 +9,34 @@ import java.util.Collections;
|
|
|
* @CreateTime: 2025-01-09 18:44
|
|
|
* @Description: 跨域处理
|
|
|
* @Version: 1.0
|
|
|
- */
|
|
|
+ * */
|
|
|
+
|
|
|
@Configuration
|
|
|
public class WebConfig {
|
|
|
- @Bean
|
|
|
- public CorsFilter corsFilter() {
|
|
|
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
- CorsConfiguration config = new CorsConfiguration();
|
|
|
- config.setAllowCredentials(true);
|
|
|
- config.setAllowedOrigins(Collections.singletonList("*")); // 允许所有域名
|
|
|
- config.setAllowedHeaders(Collections.singletonList("*"));
|
|
|
- config.setAllowedMethods(Collections.singletonList("*"));
|
|
|
- source.registerCorsConfiguration("/**", config);
|
|
|
- return new CorsFilter(source);
|
|
|
- }
|
|
|
+// @Bean
|
|
|
+// public CorsFilter corsFilter() {
|
|
|
+// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
+// CorsConfiguration config = new CorsConfiguration();
|
|
|
+// config.setAllowCredentials(true);
|
|
|
+// config.setAllowedOrigins(Collections.singletonList("*")); // 允许所有域名
|
|
|
+// config.setAllowedHeaders(Collections.singletonList("*"));
|
|
|
+// config.setAllowedMethods(Collections.singletonList("*"));
|
|
|
+// source.registerCorsConfiguration("/**", config);
|
|
|
+// return new CorsFilter(source);
|
|
|
+// }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//@Configuration
|
|
|
+//public class WebConfig implements WebMvcConfigurer {
|
|
|
+// @Override
|
|
|
+// public void addCorsMappings(CorsRegistry registry) {
|
|
|
+// registry.addMapping("/**")
|
|
|
+// .allowedOrigins("*") // 允许所有来源
|
|
|
+// .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") // 允许的方法
|
|
|
+// .allowedHeaders("*") // 允许的头部设置
|
|
|
+// .allowCredentials(true) // 是否发送cookie
|
|
|
+// .maxAge(3600); // 预检间隔时间
|
|
|
+// }
|
|
|
+//}
|