package edu.vse.configuration;

import edu.vse.filters.LoggingContextFilter;
import edu.vse.filters.RequestLoggingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FiltersConfig {

    @Bean
    public FilterRegistrationBean loggingContextFilter() {
        LoggingContextFilter loggingContextFilter = new LoggingContextFilter();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(loggingContextFilter);
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean requestLoggingFilter() {
        RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(requestLoggingFilter);
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }
}

@@ -295,16 +295,190 @@
 uration;
+%0Aimport org.springframework.web.cors.CorsConfiguration;%0Aimport org.springframework.web.cors.UrlBasedCorsConfigurationSource;%0Aimport org.springframework.web.filter.CorsFilter;
 %0A%0A@Confi
@@ -1204,11 +1204,575 @@
 n;%0A    %7D
+%0A%0A    @Bean%0A    public FilterRegistrationBean corsFilter() %7B%0A        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();%0A        CorsConfiguration config = new CorsConfiguration();%0A        config.setAllowCredentials(true);%0A        config.addAllowedOrigin(%22*%22);%0A        config.addAllowedHeader(%22*%22);%0A        config.addAllowedMethod(%22*%22);%0A        source.registerCorsConfiguration(%22/**%22, config);%0A        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));%0A        bean.setOrder(0);%0A        return bean;%0A    %7D
 %0A%7D%0A

Enable cross origin for development