package top.imwork.commons.core.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import top.imwork.commons.core.handler.BaseCoreRequestHandlerInterceptor;
import top.imwork.commons.core.utils.StringUtils;

/**
 * Copyright (C), 2015-2021
 * FileName: WebConfig
 * Author:   imwork
 * Date:     2021/2/3 15:52
 * Description: web公共配置
 * History:
 * <p>
 * 作者姓名           修改时间           版本号              描述
 */
public class WebConfig extends WebMvcConfigurationSupport {
    private final String[] defaultWhiteList = new String[] {
            "*.html", "*.js", "*.gif", "*.jpg", "*.png", "*.css", "*.ico", "/druid/*", "/doc.html", "/swagger-ui.html", "/swagger-resources",
            "/swagger-resources/**", "/v2/api-docs/**", "/webjars/springfox-swagger-ui/**", "/assets/**" };

    @Value("${silos.request.whiteList:/login}")
    private String whiteList;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        String[] addPathPatterns = { "/**" };
        String[] excludePathPatterns = new String[]{"/login"};
        if (StringUtils.isNotEmpty(this.whiteList))
            excludePathPatterns = this.whiteList.split(",");
        registry.addInterceptor(new BaseCoreRequestHandlerInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(this.defaultWhiteList).excludePathPatterns(excludePathPatterns);
    }
}
