| package com.zy.asrs.wcs.common.config; | 
|   | 
| import com.zy.asrs.wcs.common.constant.Constants; | 
| import com.zy.asrs.wcs.utils.CommonUtils; | 
| import org.springframework.context.annotation.Bean; | 
| import org.springframework.context.annotation.Configuration; | 
| import org.springframework.web.servlet.AsyncHandlerInterceptor; | 
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | 
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | 
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import javax.servlet.http.HttpServletResponse; | 
|   | 
| /** | 
|  * Created by vincent on 2019-06-13 | 
|  */ | 
| @Configuration | 
| public class WebConfig implements WebMvcConfigurer { | 
|   | 
|     @Override | 
|     public void addInterceptors(InterceptorRegistry registry) { | 
|         registry.addInterceptor(getAsyncHandlerInterceptor()) | 
|                 .addPathPatterns("/**") | 
|                 ; | 
|     } | 
|   | 
|     @Bean | 
|     public AsyncHandlerInterceptor getAsyncHandlerInterceptor() { | 
|         return new AsyncHandlerInterceptor(){ | 
|             @Override | 
|             public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | 
|                 CommonUtils.cors(response); | 
|                 return true; | 
|             } | 
|         }; | 
|     } | 
|   | 
|     @Override | 
|     public void addCorsMappings(CorsRegistry registry) { | 
|         registry.addMapping("/**") | 
|                 .allowedOriginPatterns("*") | 
|                 .allowedHeaders("*") | 
|                 .exposedHeaders(Constants.TOKEN_HEADER_NAME) | 
|                 .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH") | 
|                 .allowCredentials(true) | 
|                 .maxAge(3600); | 
|     } | 
|   | 
| } |