123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package com.its.api.webapp.config;
- import com.its.api.aop.ApiHandlerInterceptor;
- import lombok.AllArgsConstructor;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.CorsRegistry;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
- @AllArgsConstructor
- @Configuration
- public class WebConfig implements WebMvcConfigurer {
- public static final String USER_UUID = "UUID";
- public static final String USER_TIME = "TIME";
- private final ApiHandlerInterceptor apiHandlerInterceptor;
- /**
- * Controller Handler 인터셉서 등록
- * @param registry
- */
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(this.apiHandlerInterceptor)
- .addPathPatterns("/api/**") // API Controller interceptors
- .excludePathPatterns("/facility/**", "/wall/**") // 해당 경로는 인터셉터가 가로채지 않는다.
- ;
- }
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- //.allowCredentials(true)
- //.allowedOriginPatterns("*")
- .allowedOrigins("*") // 허용할 Origin(요청 url) : "*" 의 경우 모두 허용
- .allowedMethods("GET", "POST", "PUT", "DELETE") // 허용할 request http METHOD : POST, GET, DELETE, PUT
- .maxAge(3600) // 브라우저 캐시 시간(단위: 초) : "3600" 이면 최소 1시간 안에는 서버로 재요청 되지 않음
- ;
- }
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- // registry.addResourceHandler("swagger-ui.html")
- // .addResourceLocations("classpath:/META-INF/resources/");
- // registry.addResourceHandler("/webjars/**")
- // .addResourceLocations("classpath:/META-INF/resources/webjars/");
- String separator = System.getProperty("file.separator");
- String mapDataDir = System.getProperty("user.dir")+separator+"MAPDATA/";
- String downloadDir = System.getProperty("user.dir")+separator+"download/";
- registry.addResourceHandler("/MAPDATA/**")
- .addResourceLocations("file:///" + mapDataDir)
- //.setCachePeriod(60) // seconds
- ;
- registry.addResourceHandler("/download/**")
- .addResourceLocations("file:///" + downloadDir)
- //.setCachePeriod(60) // seconds
- ;
- }
- public static String encUserId(String userId) {
- return userId;
- }
- public static String decUserId(Object encUserId) {
- String decUserId = (String)encUserId;
- return decUserId;
- }
- }
|