跨域的出现:
devServer: { //nodejs服务端代理
proxy: {
host: "0.0.0.0",
port: 8088,
https: false,
hotOnly: false,
proxy: { //nodejs服务端代理
'/jacloud-web': {
target: "http://110.53.177.22:8200/jacloud-web", //目标地址 即nodejs遇到前缀开头的会在前加上该地址。
ws: true, //webSocket长连接
changeOrigin: true, //是否跨域
pathRewrite: { //路径重写 作用去掉/jacloud-web 如果前缀重复的情况.
// 原请求地址为/jacloud-web/todos 不替换时,http://110.53.177.22:8200/jacloud-web/jacloud-web/todos.
// 原请求地址为 /jacloud-web/todos 将'/jacloud-web'替换''时,
// 代理后的请求地址为:http://110.53.177.22:8200/jacloud-web/todos
"^/jacloud-web": "" //将会作用在url地址中。
}
}
}
},
id_token
在使用ningx转发代理时候会导致请求内容丢失情况。@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", ((HttpServletRequest) req).getHeader("Origin"));//解决跨域关键代码
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE,PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Disposition,Origin, X-Requested-With, Content-Type, Accept,Authorization,id_token");
response.setHeader("Access-Control-Allow-Credentials","true");
response.setHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline'; script-src 'self'; frame-ancestors 'self'; object-src 'none'");
response.setHeader("X-Content-Type-Options", "nosniff");
response.setHeader("X-XSS-Protection", "1; mode=block");
chain.doFilter(req, res);
}
简单请求:
满足以下几点是简单请求:
1、只限于get、post、head方法
2、请求头不超出以下字段(且没有其他自定义字段):
Accept
Accept-Language
Content-Language
Last-Event-ID
Content-Type:只限于三个值application/x-www-form-urlencoded、multipart/form-data、text/plain
如果不满足以上其中之一,那就是非简单请求!
非简单请求会发送一个预检请求options,用来嗅探服务端是否允许非简单请求跨域访问资源。
当然这是后端需要避免这方面的设置,避免踩坑.