WIP: thymeproxy
authorKai Moritz <kai@juplo.de>
Thu, 16 Jun 2016 14:43:36 +0000 (16:43 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 16 Jun 2016 14:43:36 +0000 (16:43 +0200)
pom.xml
src/main/java/de/juplo/thymeproxy/Application.java
src/main/resources/application.properties

diff --git a/pom.xml b/pom.xml
index 01ceb99..5d51982 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 
     <!-- application-settings -->
     <thymeproxy.name>${project.name}</thymeproxy.name>
-    <thymeproxy.origin>http://localhost:8080/</thymeproxy.origin>
+    <thymeproxy.origin>http://localhost:8080</thymeproxy.origin>
     <thymeproxy.port>8888</thymeproxy.port>
     <thymeproxy.ttl>300000</thymeproxy.ttl><!-- 5 minutes -->
+    <thymeproxy.cacheable>true</thymeproxy.cacheable>
     <httpclient.logging.level>ERROR</httpclient.logging.level>
 
     <!-- used versions (not defined in spring-boot) -->
index 66557b9..dcc35f8 100644 (file)
@@ -8,6 +8,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.Ordered;
 import org.springframework.core.env.Environment;
+import org.springframework.web.servlet.mvc.UrlFilenameViewController;
+import org.thymeleaf.resourceresolver.IResourceResolver;
+import org.thymeleaf.resourceresolver.UrlResourceResolver;
+import org.thymeleaf.templateresolver.TemplateResolver;
 
 
 @SpringBootApplication
@@ -15,23 +19,24 @@ public class Application
 {
   @Bean
   public RegexUrlHandlerMapping proxiedHandlerMapping(
-      ProxyHttpRequestHandler handler
+      ProxyHttpRequestHandler proxy,
+      UrlFilenameViewController views
       )
   {
     RegexUrlHandlerMapping mapping = new RegexUrlHandlerMapping();
     mapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
     Map<String, Object> mappings = new HashMap<>();
-    mappings.put(".*\\.html$", handler);
-    mappings.put("/css/.+", handler);
-    mappings.put("/js/.+", handler);
-    mappings.put("/fonts/.+", handler);
-    mappings.put("/.+/", handler);
+    mappings.put("/thymeleaf/.*\\.html", proxy);
+    mappings.put("/css/.+", proxy);
+    mappings.put("/js/.+", proxy);
+    mappings.put("/fonts/.+", proxy);
+    mappings.put(".*\\.html", views);
     mapping.setUrlMap(mappings);
        return mapping;
   }
 
   @Bean
-  public ProxyHttpRequestHandler proxiedRequestHandler(
+  public ProxyHttpRequestHandler proxyHttpRequestHandler(
       CloseableHttpClient client,
       Environment env
       )
@@ -43,6 +48,34 @@ public class Application
     return handler;
   }
 
+  @Bean
+  public UrlFilenameViewController urlFilenameViewController()
+  {
+    return new UrlFilenameViewController();
+  }
+
+  @Bean
+  public TemplateResolver defaultTemplateResolver(
+      IResourceResolver resources,
+      Environment env
+      )
+  {
+    TemplateResolver resolver = new TemplateResolver();
+    resolver.setResourceResolver(resources);
+    resolver.setPrefix("//thymeleaf/");
+    resolver.setSuffix(".html");
+    resolver.setTemplateMode("HTML5");
+    resolver.setCharacterEncoding("UTF-8");
+    resolver.setCacheable(Boolean.valueOf(env.getProperty("thymeproxy.cacheable")));
+    return resolver;
+  }
+
+  @Bean
+  public UrlResourceResolver thymeleafResourceResolver()
+  {
+    return new UrlResourceResolver();
+  }
+
 
   public static void main(String[] args)
   {
index 0a4144f..c0d3372 100644 (file)
@@ -3,6 +3,7 @@ thymeproxy.origin=@thymeproxy.origin@
 server.port=@thymeproxy.port@
 thymeproxy.ttl=@thymeproxy.ttl@
 thymeproxy.origins[0].uri=http://localhost:8080/thymeleaf/
+thymeproxy.cacheable=@thymeproxy.cacheable@
 
 logging.level.de.juplo=info
 logging.level.org.apache.http=@httpclient.logging.level@