解决两个问题:
1、config.js中写错URL导致axios请求失败; 2、axios为CROS发送两次请求,第一次的method是options,在token过滤器中需要忽略。
This commit is contained in:
		@@ -2,8 +2,8 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2023-01-29 10:39:41
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2023-01-29 10:39:44
 | 
			
		||||
 * @FilePath: \requirement\src\main\java\com\cpic\xim\web\filters\cros\CrosFilter.java
 | 
			
		||||
 * @LastEditTime: 2023-02-04 17:12:05
 | 
			
		||||
 * @FilePath: /后端-需求/src/main/java/com/cpic/xim/web/filters/cros/CrosFilter.java
 | 
			
		||||
 * @Description: 过滤器,用于对CROS访问进行响应。允许任何来源的访问。
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
@@ -33,7 +33,7 @@ public class CrosFilter implements Filter
 | 
			
		||||
        response.setHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE" );
 | 
			
		||||
        response.setHeader( "Access-Control-Max-Age", "0" );
 | 
			
		||||
        response.setHeader( "Access-Control-Allow-Headers",
 | 
			
		||||
                "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token" );
 | 
			
		||||
                "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token,username" );
 | 
			
		||||
        response.setHeader( "Access-Control-Allow-Credentials", "true" );
 | 
			
		||||
        response.setHeader( "XDomainRequestAllowed", "1" );
 | 
			
		||||
        response.setHeader( "XDomainRequestAllowed", "1" );
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2023-01-29 10:50:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2023-01-29 10:55:27
 | 
			
		||||
 * @FilePath: \requirement\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java
 | 
			
		||||
 * @LastEditTime: 2023-02-04 18:05:18
 | 
			
		||||
 * @FilePath: /后端-需求/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java
 | 
			
		||||
 * @Description: 
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
@@ -11,6 +11,7 @@
 | 
			
		||||
package com.cpic.xim.web.filters.token;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.Enumeration;
 | 
			
		||||
import javax.servlet.Filter;
 | 
			
		||||
import javax.servlet.FilterChain;
 | 
			
		||||
import javax.servlet.ServletException;
 | 
			
		||||
@@ -19,9 +20,11 @@ import javax.servlet.ServletResponse;
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings( "unused")
 | 
			
		||||
@SuppressWarnings( "unused" )
 | 
			
		||||
public class TokenFilter implements Filter
 | 
			
		||||
{
 | 
			
		||||
    private static final String FILTE_METHODS = "POST,GET";
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )
 | 
			
		||||
            throws ServletException, IOException
 | 
			
		||||
@@ -29,8 +32,14 @@ public class TokenFilter implements Filter
 | 
			
		||||
        HttpServletRequest request = (HttpServletRequest) req;
 | 
			
		||||
        HttpServletResponse response = (HttpServletResponse) resp;
 | 
			
		||||
 | 
			
		||||
        // 获取请求中的token字符串
 | 
			
		||||
        String token = request.getHeader( "Token" );
 | 
			
		||||
        String method = request.getMethod().toUpperCase();
 | 
			
		||||
 | 
			
		||||
        // 只处理POST和GET
 | 
			
		||||
        if ( FILTE_METHODS.indexOf( method ) != -1 )
 | 
			
		||||
        {
 | 
			
		||||
            // 检查token
 | 
			
		||||
            String token = request.getHeader( "token" );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        chain.doFilter( request, response );
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user