| package org.eclipse.openk.gridfailureinformation.config; |
| |
| import lombok.extern.log4j.Log4j2; |
| import org.springframework.beans.factory.annotation.Value; |
| import org.springframework.context.annotation.Bean; |
| import org.springframework.context.annotation.Configuration; |
| import org.springframework.web.servlet.config.annotation.CorsRegistry; |
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| |
| @Log4j2 |
| @Configuration |
| public class CorsConfig { |
| |
| @Value("${cors.corsEnabled}") |
| private boolean corsEnabled; |
| |
| @Bean |
| public WebMvcConfigurer corsConfigurer() { |
| return new WebMvcConfigurer() { |
| @Override |
| public void addCorsMappings(CorsRegistry registry) { |
| if (corsEnabled) { |
| log.info("Cors enabled"); |
| registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE").allowedOrigins("*") |
| .allowedHeaders("*"); |
| } else { |
| log.info("Cors disabled"); |
| } |
| } |
| }; |
| } |
| } |