From 13237626f3956d93a91a94bee6fee6aa86134a06 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 27 Mar 2018 22:13:16 +0300 Subject: www: spring boot autoconfigured static resources + cache busting using Spring --- juick-www/src/main/java/com/juick/www/WebApp.java | 25 ++++------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www/WebApp.java') diff --git a/juick-www/src/main/java/com/juick/www/WebApp.java b/juick-www/src/main/java/com/juick/www/WebApp.java index 94c12528..4e8b3a11 100644 --- a/juick-www/src/main/java/com/juick/www/WebApp.java +++ b/juick-www/src/main/java/com/juick/www/WebApp.java @@ -16,20 +16,16 @@ */ package com.juick.www; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.Tag; import com.juick.service.TagService; -import org.apache.commons.io.IOUtils; import org.springframework.stereotype.Component; +import org.springframework.web.servlet.resource.ResourceUrlProvider; import javax.annotation.PostConstruct; import javax.inject.Inject; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.stream.Stream; @@ -42,20 +38,7 @@ public class WebApp { @Inject private TagService tagService; @Inject - private ObjectMapper jsonMapper; - - private String scriptsUrl; - private String styleUrl; - - @PostConstruct - public void init() throws IOException { - String manifestString = IOUtils.toString(getClass().getClassLoader(). - getResourceAsStream("manifest.json"), StandardCharsets.UTF_8); - HashMap manifest = jsonMapper.readValue(manifestString, - new TypeReference>() {}); - scriptsUrl = manifest.get("scripts.js"); - styleUrl = manifest.get("style.css"); - } + private ResourceUrlProvider resourceUrlProvider; public List parseTags(String tagsStr) { List tags = new ArrayList<>(); @@ -79,10 +62,10 @@ public class WebApp { } public String getStyleUrl() { - return styleUrl; + return resourceUrlProvider.getForLookupPath("/style.css"); } public String getScriptsUrl() { - return scriptsUrl; + return resourceUrlProvider.getForLookupPath("/scripts.js"); } } -- cgit v1.2.3