package com.das.common.config;

import com.das.common.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor getTokenInterceptor() {
        return new TokenInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将Token拦截器添加到注册表中
        registry.addInterceptor(getTokenInterceptor())
                // 可以指定拦截哪些路径，例如"/api/**"表示所有以/api开头的路径
//                .addPathPatterns("/api/**");
                // 排除不需要拦截的路径
                .excludePathPatterns("/api/**");
    }
}
