diff --git a/src/main/java/com/mobile_education_platform/config/Swagger2Config.java b/src/main/java/com/mobile_education_platform/config/Swagger2Config.java index a76c1915bde98f16c2a3ac26732b9ea9ab353527..9199f8e1c417438c3152f71fd365633b92b1e572 100644 --- a/src/main/java/com/mobile_education_platform/config/Swagger2Config.java +++ b/src/main/java/com/mobile_education_platform/config/Swagger2Config.java @@ -23,13 +23,14 @@ public class Swagger2Config extends WebMvcConfigurationSupport { * @Description: 默认文档地址为 http://localhost:8083/swagger-ui.html * @param * @return - * @Author: Chen si ran + * @Author: Chen si ran * @Date: 2021/10/25 13:44 **/ @Bean public Docket docket(Environment environment) { return new Docket(DocumentationType.SWAGGER_2) + .host("8.129.77.49:8083") //.groupName("元架构-教学平台-前台") .apiInfo(apiInfo()) .enable(true) diff --git a/src/main/java/com/mobile_education_platform/filter/AllowOriginFilter.java b/src/main/java/com/mobile_education_platform/filter/AllowOriginFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..7aae8ddd9ab868870ccd308d90409136b69a5e08 --- /dev/null +++ b/src/main/java/com/mobile_education_platform/filter/AllowOriginFilter.java @@ -0,0 +1,32 @@ +package com.mobile_education_platform.filter; + +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class AllowOriginFilter implements Filter { + + @SuppressWarnings("unused") + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + HttpServletResponse response = (HttpServletResponse) res; + HttpServletRequest request = (HttpServletRequest) req; + response.setHeader("Access-Control-Allow-Origin", ((HttpServletRequest) req).getHeader("Origin")); // 设置允许所有跨域访问 + response.setHeader("Access-Control-Allow-Methods", "POST,GET,PUT,PATCH,OPTIONS,DELETE"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,Authorization,token"); + response.setHeader("Access-Control-Allow-Credentials", "true"); + chain.doFilter(req, res); + } + + public void init(FilterConfig filterConfig) { + } + + public void destroy() { + } + + +} \ No newline at end of file