Browse Source

跨域请求

陈长荣 5 months ago
parent
commit
89b93ef18b

+ 6 - 14
jfcloud-gene-biz/src/main/java/com/github/jfcloud/gene/config/CorsConfig.java

@@ -1,13 +1,11 @@
 package com.github.jfcloud.gene.config;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
-/**
- * @author zj
- * @date 2022/6/20
- */
+@Slf4j
 @Configuration
 public class CorsConfig implements WebMvcConfigurer {
 
@@ -15,16 +13,10 @@ public class CorsConfig implements WebMvcConfigurer {
     public void addCorsMappings(CorsRegistry registry) {
         //解决跨域问题
         registry.addMapping("/**")
-                .allowedOrigins("*")
-                .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
+                .allowedOriginPatterns("*")
+                .allowedMethods("*")
                 .allowedHeaders("*")
-                .exposedHeaders("access-control-allow-headers",
-                        "access-control-allow-methods",
-                        "access-control-allow-origin",
-                        "access-control-max-age",
-                        "X-Frame-Options")
-                .allowCredentials(false)
-                .maxAge(3600);
-        WebMvcConfigurer.super.addCorsMappings(registry);
+                .allowCredentials(true);
     }
 }
+

+ 1 - 2
jfcloud-gene-biz/src/main/resources/application.yml

@@ -18,5 +18,4 @@ logging:
                 filter: warn
 
 knife4j:
-  enable: true
-  cors: true
+  enable: true