From aa19744ae40767b2523ac0117792b47e08209cdf Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Jun 2017 15:37:09 +0300 Subject: Webpack 3, chunknames in templates --- .../www/configuration/WwwAppConfiguration.java | 22 +++++++++++++++++++--- .../www/configuration/WwwServletConfiguration.java | 6 +++--- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/configuration') diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java index 2cf1faed..a5bc3f73 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java @@ -1,13 +1,16 @@ package com.juick.www.configuration; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.www.HelpService; -import com.juick.www.controllers.PageTemplates; import com.juick.www.WebApp; +import com.juick.www.controllers.PageTemplates; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; @@ -17,6 +20,9 @@ import org.springframework.core.env.Environment; import javax.annotation.Resource; import javax.inject.Inject; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; /** * Created by aalexeev on 11/22/16. @@ -31,10 +37,20 @@ public class WwwAppConfiguration { private UserService userService; @Inject private TagService tagService; + @Inject + private ObjectMapper jsonMapper; + @Value("#{servletContext.contextPath}") + private String servletContextPath; @Bean - public WebApp webApp() { - return new WebApp(env, templates(), userService, tagService); + public WebApp webApp() throws IOException { + WebApp app = new WebApp(); + String manifestString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("manifest.json"), StandardCharsets.UTF_8); + HashMap manifest = jsonMapper.readValue(manifestString, + new TypeReference>() {}); + app.setScriptsUrl(manifest.get("scripts.js")); + app.setStyleUrl(manifest.get("style.css")); + return app; } @Bean public PageTemplates templates() { diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 43ca37db..ae51f1cd 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -38,11 +38,11 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.setOrder(0); registry.addResourceHandler( - "/scripts.js*", - "/style.css*", + "/scripts*.js*", + "/style*.css*", "/*.png", "/favicon.ico") - .addResourceLocations("/") + .addResourceLocations("classpath:/") .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()) .resourceChain(true) .addResolver(new PathResourceResolver()); -- cgit v1.2.3