Raod 3 years ago
parent 4f6fa35070
commit 3a97a02bce

@ -1,10 +1,11 @@
package com.anjiplus.template.gaea.business.filter; package com.anjiplus.template.gaea.business.filter;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -13,6 +14,7 @@ import java.io.IOException;
*/ */
@Configuration @Configuration
@WebFilter(filterName = "CorsFilter ") @WebFilter(filterName = "CorsFilter ")
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CORSFilter implements Filter { public class CORSFilter implements Filter {
@Override @Override
@ -26,11 +28,10 @@ public class CORSFilter implements Filter {
// 设置允许跨域请求的方法 // 设置允许跨域请求的方法
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
// 允许跨域请求包含content-type // 允许跨域请求包含content-type
res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN"); res.addHeader("Access-Control-Allow-Headers", "*");
if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) { // if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
response.getWriter().println("ok"); // response.getWriter().println("ok");
return; // }
}
chain.doFilter(request, response); chain.doFilter(request, response);
} }

@ -9,7 +9,8 @@ const service = axios.create({
withCredentials: false, withCredentials: false,
timeout: 60000, timeout: 60000,
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
'Authorization': getItem('token')
} }
}) })

Loading…
Cancel
Save