WebConfig.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.its.api.webapp.config;
  2. import com.its.api.aop.ApiHandlerInterceptor;
  3. import lombok.AllArgsConstructor;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  6. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  7. import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  8. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  9. @AllArgsConstructor
  10. @Configuration
  11. public class WebConfig implements WebMvcConfigurer {
  12. public static final String USER_UUID = "UUID";
  13. public static final String USER_TIME = "TIME";
  14. private final ApiHandlerInterceptor apiHandlerInterceptor;
  15. /**
  16. * Controller Handler 인터셉서 등록
  17. * @param registry
  18. */
  19. @Override
  20. public void addInterceptors(InterceptorRegistry registry) {
  21. registry.addInterceptor(this.apiHandlerInterceptor)
  22. .addPathPatterns("/api/**") // API Controller interceptors
  23. .excludePathPatterns("/facility/**", "/wall/**") // 해당 경로는 인터셉터가 가로채지 않는다.
  24. ;
  25. }
  26. @Override
  27. public void addCorsMappings(CorsRegistry registry) {
  28. registry.addMapping("/**")
  29. //.allowCredentials(true)
  30. //.allowedOriginPatterns("*")
  31. .allowedOrigins("*") // 허용할 Origin(요청 url) : "*" 의 경우 모두 허용
  32. .allowedMethods("GET", "POST", "PUT", "DELETE") // 허용할 request http METHOD : POST, GET, DELETE, PUT
  33. .maxAge(3600) // 브라우저 캐시 시간(단위: 초) : "3600" 이면 최소 1시간 안에는 서버로 재요청 되지 않음
  34. ;
  35. }
  36. @Override
  37. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  38. // registry.addResourceHandler("swagger-ui.html")
  39. // .addResourceLocations("classpath:/META-INF/resources/");
  40. // registry.addResourceHandler("/webjars/**")
  41. // .addResourceLocations("classpath:/META-INF/resources/webjars/");
  42. String separator = System.getProperty("file.separator");
  43. String mapDataDir = System.getProperty("user.dir")+separator+"MAPDATA/";
  44. String downloadDir = System.getProperty("user.dir")+separator+"download/";
  45. registry.addResourceHandler("/MAPDATA/**")
  46. .addResourceLocations("file:///" + mapDataDir)
  47. //.setCachePeriod(60) // seconds
  48. ;
  49. registry.addResourceHandler("/download/**")
  50. .addResourceLocations("file:///" + downloadDir)
  51. //.setCachePeriod(60) // seconds
  52. ;
  53. }
  54. public static String encUserId(String userId) {
  55. return userId;
  56. }
  57. public static String decUserId(Object encUserId) {
  58. String decUserId = (String)encUserId;
  59. return decUserId;
  60. }
  61. }