yaobo 7 роки тому
батько
коміт
ca8bbe12ee

+ 38 - 38
src/main/java/cn/efunbox/audio/aop/CorsFilter.java

@@ -1,38 +1,38 @@
-//package cn.efunbox.audio.aop;
-//
-//import org.springframework.stereotype.Component;
-//
-//import javax.servlet.*;
-//import javax.servlet.http.HttpServletRequest;
-//import javax.servlet.http.HttpServletResponse;
-//import java.io.IOException;
-//
-///**
-// *
-// *  允许跨域访问过滤器
-// * @author meng
-// * @version
-// * @since 2016年6月19日
-// */
-//@Component
-//public class CorsFilter implements Filter {
-//
-//    final static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CorsFilter.class);
-//
-//    @Override
-//    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
-//        HttpServletResponse response = (HttpServletResponse) res;
-//
-//        HttpServletRequest reqs = (HttpServletRequest) req;
-//
-////        System.out.println("access from "+reqs.getHeader("Origin"));
-//        response.setHeader("Access-Control-Allow-Origin",reqs.getHeader("Origin")); //直接用"*"无法解决跨域问题
-//        response.setHeader("Access-Control-Allow-Credentials", "true");
-//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
-//        response.setHeader("Access-Control-Max-Age", "3600");
-//        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
-//        chain.doFilter(req, res);
-//    }
-//    public void init(FilterConfig filterConfig) {}
-//    public void destroy() {}
-//}
+package cn.efunbox.audio.aop;
+
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ *
+ *  允许跨域访问过滤器
+ * @author meng
+ * @version
+ * @since 2016年6月19日
+ */
+@Component
+public class CorsFilter implements Filter {
+
+    final static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CorsFilter.class);
+
+    @Override
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
+        HttpServletResponse response = (HttpServletResponse) res;
+
+        HttpServletRequest reqs = (HttpServletRequest) req;
+
+//        System.out.println("access from "+reqs.getHeader("Origin"));
+        response.setHeader("Access-Control-Allow-Origin",reqs.getHeader("Origin")); //直接用"*"无法解决跨域问题
+        response.setHeader("Access-Control-Allow-Credentials", "true");
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, OPTIONS");
+        response.setHeader("Access-Control-Max-Age", "3600");
+        response.setHeader("Access-Control-Allow-Headers", "x-requested-with, id, token");
+        chain.doFilter(req, res);
+    }
+    public void init(FilterConfig filterConfig) {}
+    public void destroy() {}
+}

+ 13 - 13
src/main/java/cn/efunbox/audio/config/Config.java

@@ -49,18 +49,18 @@ public class Config extends WebMvcConfigurerAdapter{
                 .excludePathPatterns("/device/**", "/admin/login", "/audio/search");
     }
 
-    /**
-     * 允许跨域访问
-     * @param registry
-     */
-    @Override
-    public void addCorsMappings(CorsRegistry registry) {
-        registry.addMapping("/**")
-                .allowedOrigins("*")
-                .allowCredentials(true)
-                .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
-                .allowedHeaders("*")
-                .maxAge(3600);
-    }
+//    /**
+//     * 允许跨域访问
+//     * @param registry
+//     */
+//    @Override
+//    public void addCorsMappings(CorsRegistry registry) {
+//        registry.addMapping("/**")
+//                .allowedOrigins("*")
+//                .allowCredentials(true)
+//                .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
+//                .allowedHeaders("*")
+//                .maxAge(3600);
+//    }
 
 }