zzw
1 天以前 f651ad5716aa86afafc16e8abe342ed7ddd9d986
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.emergencyrepair.config;
 
import com.emergencyrepair.common.audit.CurrentUserInterceptor;
import org.springframework.context.annotation.Configuration;
import com.emergencyrepair.system.log.OperationLogInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@RequiredArgsConstructor
@Configuration
public class WebConfig implements WebMvcConfigurer {
    private final CurrentUserInterceptor currentUserInterceptor;
    private final OperationLogInterceptor operationLogInterceptor;
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(currentUserInterceptor).addPathPatterns("/api/**").order(0);
        registry.addInterceptor(operationLogInterceptor).addPathPatterns("/api/**");
    }
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}