package com.backendsys.modules.common.config;

import com.backendsys.modules.common.interceptor.ApiLogInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${API_LOG}")
    private Boolean API_LOG;

    @Autowired
    private ApiLogInterceptor apiLogInterceptor;        // 日志拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // [拦截器] API日志
        if (API_LOG) registry.addInterceptor(apiLogInterceptor);
    }

    // 静态资源映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/static/images/");
    }

}
