/*
 * Copyright 2016 EPAM Systems
 * 
 * 
 * This file is part of EPAM Report Portal.
 * https://github.com/reportportal/service-ui
 * 
 * Report Portal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Report Portal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Report Portal.  If not, see <http://www.gnu.org/licenses/>.
 */ 

package com.epam.reportportal.ui;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Gateway Application
 *
 * @author Andrei Varabyeu
 */
@SpringBootApplication
@EnableEurekaClient
public class UIApp extends WebMvcConfigurerAdapter {

	public static void main(String[] args) throws Exception {
		SpringApplication.run(UIApp.class, args);
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		if (!registry.hasMappingForPattern("/webjars/**")) {
			registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
		}
		if (!registry.hasMappingForPattern("/**")) {
			registry.addResourceHandler("/**").addResourceLocations("classpath:/public/");
		}
	}

	@Component
	public class WebConfiguration implements EmbeddedServletContainerCustomizer {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
			configurableEmbeddedServletContainer.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
		}
	}

}

@@ -783,17 +783,16 @@
 s/%3E.%0A */
- 
 %0A%0Apackag
@@ -1231,24 +1231,70 @@
 rekaClient;%0A
+import org.springframework.http.CacheControl;%0A
 import org.s
@@ -1884,16 +1884,338 @@
 stry) %7B%0A
+%09%09/* do not cache htmls */%0A%09%09registry.addResourceHandler(%22*.html%22, %22*.htm%22).addResourceLocations(%22classpath:/public/%22).setCacheControl(CacheControl.noCache());%0A%0A%09%09/* non-expiring cache for other statics */%0A%09%09registry.addResourceHandler(%22/**%22).addResourceLocations(%22classpath:/public/%22).setCachePeriod(Integer.MAX_VALUE);%0A%0A
 %09%09if (!r
@@ -2379,141 +2379,8 @@
 %09%09%7D%0A
-%09%09if (!registry.hasMappingForPattern(%22/**%22)) %7B%0A%09%09%09registry.addResourceHandler(%22/**%22).addResourceLocations(%22classpath:/public/%22);%0A%09%09%7D%0A
 %09%7D%0A%0A

update cache configuration