package com.sckw.core.config;

import com.sckw.core.interceptor.AuthenticationInterceptor;
import com.sckw.core.web.constant.CommonConstants;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 认证拦截器配置
 */
@ConditionalOnClass(WebMvcConfigurer.class)
@Configuration
public class AuthInterceptorConfig implements WebMvcConfigurer {
    @Resource
    private ProjectConfig projectConfig;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义拦截器实例，并指定拦截的路径模式
        registry.addInterceptor(new AuthenticationInterceptor()).addPathPatterns("/**"); // 可以排除某些路径不被拦截
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(CommonConstants.RESOURCE_PREFIX + "/**")
                .addResourceLocations("file:" + projectConfig.getProfile() + "/");
    }
}
