// Path: server/src/main/java/com/mycompany/myapp/web/filter/ApiOriginFilter.java
// public class ApiOriginFilter implements javax.servlet.Filter {
//     @Override
//     public void doFilter(ServletRequest request, ServletResponse response,
//                          FilterChain chain) throws IOException, ServletException {
//         HttpServletResponse res = (HttpServletResponse) response;
//         res.addHeader("Access-Control-Allow-Origin", "*");
//         res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
//         res.addHeader("Access-Control-Allow-Headers", "Content-Type");
//         chain.doFilter(request, response);
//     }
// 
//     @Override
//     public void destroy() {
//     }
// 
//     @Override
//     public void init(FilterConfig filterConfig) throws ServletException {
//     }
// }


import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.servlet.InstrumentedFilter;
import com.codahale.metrics.servlets.MetricsServlet;
import com.mycompany.myapp.web.filter.ApiOriginFilter;
import com.mycompany.myapp.web.filter.CachingHttpHeadersFilter;
import com.mycompany.myapp.web.filter.StaticResourcesProductionFilter;
import com.mycompany.myapp.web.filter.gzip.GZipServletFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.inject.Inject;
import javax.servlet.*;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

    /**
     * Initializes the static resources production Filter.
     */
    private void initStaticResourcesProductionFilter(ServletContext servletContext,
                                                     EnumSet<DispatcherType> disps) {

        log.debug("Registering static resources production Filter");
        FilterRegistration.Dynamic staticResourcesProductionFilter =
                servletContext.addFilter("staticResourcesProductionFilter",
                        new StaticResourcesProductionFilter());

        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/index.html");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/assets/*");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
        staticResourcesProductionFilter.setAsyncSupported(true);
    }

    /**
     * Initializes the caching HTTP Headers Filter.
     */
    private void initCachingHttpHeadersFilter(ServletContext servletContext,
                                              EnumSet<DispatcherType> disps) {
        log.debug("Registering Caching HTTP Headers Filter");
        FilterRegistration.Dynamic cachingHttpHeadersFilter =
                servletContext.addFilter("cachingHttpHeadersFilter",
                        new CachingHttpHeadersFilter(env));

        cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/assets/*");
// Path: server/src/main/java/com/mycompany/myapp/web/filter/ApiOriginFilter.java
// public class ApiOriginFilter implements javax.servlet.Filter {
//     @Override
//     public void doFilter(ServletRequest request, ServletResponse response,
//                          FilterChain chain) throws IOException, ServletException {
//         HttpServletResponse res = (HttpServletResponse) response;
//         res.addHeader("Access-Control-Allow-Origin", "*");
//         res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
//         res.addHeader("Access-Control-Allow-Headers", "Content-Type");
//         chain.doFilter(request, response);
//     }
// 
//     @Override
//     public void destroy() {
//     }
// 
//     @Override
//     public void init(FilterConfig filterConfig) throws ServletException {
//     }
// }


// Path: server/src/main/java/com/mycompany/myapp/config/WebConfigurer.java
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.servlet.InstrumentedFilter;
import com.codahale.metrics.servlets.MetricsServlet;
import com.mycompany.myapp.web.filter.ApiOriginFilter;
import com.mycompany.myapp.web.filter.CachingHttpHeadersFilter;
import com.mycompany.myapp.web.filter.StaticResourcesProductionFilter;
import com.mycompany.myapp.web.filter.gzip.GZipServletFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import javax.inject.Inject;
import javax.servlet.*;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;


    /**
     * Initializes the static resources production Filter.
     */
    private void initStaticResourcesProductionFilter(ServletContext servletContext,
                                                     EnumSet<DispatcherType> disps) {

        log.debug("Registering static resources production Filter");
        FilterRegistration.Dynamic staticResourcesProductionFilter =
                servletContext.addFilter("staticResourcesProductionFilter",
                        new StaticResourcesProductionFilter());

        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/index.html");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/assets/*");
        staticResourcesProductionFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");
        staticResourcesProductionFilter.setAsyncSupported(true);
    }

    /**
     * Initializes the caching HTTP Headers Filter.
     */
    private void initCachingHttpHeadersFilter(ServletContext servletContext,
                                              EnumSet<DispatcherType> disps) {
        log.debug("Registering Caching HTTP Headers Filter");
        FilterRegistration.Dynamic cachingHttpHeadersFilter =
                servletContext.addFilter("cachingHttpHeadersFilter",
                        new CachingHttpHeadersFilter(env));

        cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/assets/*");
        cachingHttpHeadersFilter.addMappingForUrlPatterns(disps, true, "/scripts/*");