|
|
@@ -1,55 +1,55 @@
|
|
|
-package cn.seecoder.seecoderbokserver.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;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author: Leonezhurui
|
|
|
- * @Date: 2021/8/21 - 11:20 下午
|
|
|
- * @Package: SEEC-BOK
|
|
|
- */
|
|
|
-
|
|
|
-@Configuration
|
|
|
-public class CorsConfig {
|
|
|
- private static String[] originsVal =
|
|
|
- new String[] {
|
|
|
- "localhost:8002",
|
|
|
- "localhost:8080",
|
|
|
- "localhost:8000",
|
|
|
- "127.0.0.1:8002",
|
|
|
- "127.0.0.1:8000",
|
|
|
- "127.0.0.1:8080",
|
|
|
- "127.0.0.1",
|
|
|
- "bok.seec.seecoder.cn",
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- @Bean
|
|
|
- public CorsFilter corsFilter() {
|
|
|
- final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
|
|
- final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
|
- addAllowedOrigins(corsConfiguration);
|
|
|
- // 允许token放置于请求头
|
|
|
- corsConfiguration.addExposedHeader("Authorization");
|
|
|
- /*是否允许请求带有验证信息*/
|
|
|
- corsConfiguration.setAllowCredentials(true);
|
|
|
- /*允许访问的客户端域名*/
|
|
|
-// corsConfiguration.addAllowedOrigin("*");
|
|
|
- /*允许服务端访问的客户端请求头*/
|
|
|
- corsConfiguration.addAllowedHeader("*");
|
|
|
- /*允许访问的方法名,GET POST等*/
|
|
|
- corsConfiguration.addAllowedMethod("*");
|
|
|
- urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
|
|
- return new CorsFilter(urlBasedCorsConfigurationSource);
|
|
|
- }
|
|
|
-
|
|
|
- private void addAllowedOrigins(CorsConfiguration corsConfiguration) {
|
|
|
- for (String origin : originsVal) {
|
|
|
- corsConfiguration.addAllowedOrigin("http://" + origin);
|
|
|
- corsConfiguration.addAllowedOrigin("https://" + origin);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//package cn.seecoder.seecoderbokserver.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;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @author: Leonezhurui
|
|
|
+// * @Date: 2021/8/21 - 11:20 下午
|
|
|
+// * @Package: SEEC-BOK
|
|
|
+// */
|
|
|
+//
|
|
|
+//@Configuration
|
|
|
+//public class CorsConfig {
|
|
|
+// private static String[] originsVal =
|
|
|
+// new String[] {
|
|
|
+// "localhost:8002",
|
|
|
+// "localhost:8080",
|
|
|
+// "localhost:8000",
|
|
|
+// "127.0.0.1:8002",
|
|
|
+// "127.0.0.1:8000",
|
|
|
+// "127.0.0.1:8080",
|
|
|
+// "127.0.0.1",
|
|
|
+// "bok.seec.seecoder.cn",
|
|
|
+// };
|
|
|
+//
|
|
|
+//
|
|
|
+// @Bean
|
|
|
+// public CorsFilter corsFilter() {
|
|
|
+// final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
|
|
+// final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
|
+// addAllowedOrigins(corsConfiguration);
|
|
|
+// // 允许token放置于请求头
|
|
|
+// corsConfiguration.addExposedHeader("Authorization");
|
|
|
+// /*是否允许请求带有验证信息*/
|
|
|
+// corsConfiguration.setAllowCredentials(true);
|
|
|
+// /*允许访问的客户端域名*/
|
|
|
+//// corsConfiguration.addAllowedOrigin("*");
|
|
|
+// /*允许服务端访问的客户端请求头*/
|
|
|
+// corsConfiguration.addAllowedHeader("*");
|
|
|
+// /*允许访问的方法名,GET POST等*/
|
|
|
+// corsConfiguration.addAllowedMethod("*");
|
|
|
+// urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
|
|
+// return new CorsFilter(urlBasedCorsConfigurationSource);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private void addAllowedOrigins(CorsConfiguration corsConfiguration) {
|
|
|
+// for (String origin : originsVal) {
|
|
|
+// corsConfiguration.addAllowedOrigin("http://" + origin);
|
|
|
+// corsConfiguration.addAllowedOrigin("https://" + origin);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|