321121254
2018-12-08 01:33
可以不可以后端不做跨域的任何处理,全部让前端来做,比如Nginx?
可以前端做,但是一般都是后端做,写一个统一过滤器也可以
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
chain.doFilter(req, res);
}
可以用 openresty
SpringBoot构建电商基础秒杀项目
49064 学习 · 954 问题
相似问题