package com.persagy.proxy.common.config;

import com.persagy.dmp.auth.handler.AppContextHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器
 * @author Charlie Yu
 * @date 2021-09-13
 */
@Configuration
@Order(1)
@EnableAsync
public class AdmMiddlewareWebConfigurer implements WebMvcConfigurer {

    @Bean
    public AppContextHandler appContextHandler() {
        return new AppContextHandler();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] includePaths = {"/**"};
        String[] excludePaths = {"/**/*.html", "/**/*.js", "/**/*.css", "/swagger-resources"};
        // 设置拦截的路径、不拦截的路径、优先级等等
        registry.addInterceptor(appContextHandler()).order(11).addPathPatterns(includePaths).excludePathPatterns(excludePaths);
    }
}
