package com.zanxiang.game.module.sdk.config;

import com.zanxiang.game.module.sdk.adapter.WebHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : lingfeng
 * @time : 2022-09-28
 * @description : 拦截器配置
 */
@Configuration
public class AdapterHandlerConfig implements WebMvcConfigurer {

    @Autowired
    private WebHandlerAdapter webAdapterHandler;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //定义排除swagger访问的路径配置
        String[] swaggerExcludes = new String[]{"/swagger-ui.html", "/swagger-resources/**", "/webjars/**"};
        // 对所有访问路径，都通过MyInterceptor类型的拦截器进行拦截
        registry.addInterceptor(webAdapterHandler)
                .addPathPatterns("/**")
                //排除
                .excludePathPatterns(swaggerExcludes);
        //初始化
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
