diff options
author | Vitaly Takmazov | 2018-03-27 22:13:16 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-27 22:22:35 +0300 |
commit | 13237626f3956d93a91a94bee6fee6aa86134a06 (patch) | |
tree | 50634fdfb2fddc924d60be18886184f49b2f7115 /juick-www/src/main | |
parent | cc551432bf80e4466b92c42a77a094f31408abeb (diff) |
www: spring boot autoconfigured static resources
+ cache busting using Spring
Diffstat (limited to 'juick-www/src/main')
-rw-r--r-- | juick-www/src/main/assets/embed.js (renamed from juick-www/src/main/js/killy/index.js) | 0 | ||||
-rw-r--r-- | juick-www/src/main/assets/logo.png (renamed from juick-www/src/main/static/logo.png) | bin | 2447 -> 2447 bytes | |||
-rw-r--r-- | juick-www/src/main/assets/logo@2x.png (renamed from juick-www/src/main/static/logo@2x.png) | bin | 4822 -> 4822 bytes | |||
-rw-r--r-- | juick-www/src/main/assets/scripts.js (renamed from juick-www/src/main/static/scripts.js) | 2 | ||||
-rw-r--r-- | juick-www/src/main/assets/style.css (renamed from juick-www/src/main/static/style.css) | 0 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/WebApp.java | 25 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java | 3 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java | 22 | ||||
-rw-r--r-- | juick-www/src/main/js/killy/package.json | 6 | ||||
-rw-r--r-- | juick-www/src/main/resources/static/favicon.png (renamed from juick-www/src/main/resources/favicon.png) | bin | 244 -> 244 bytes | |||
-rw-r--r-- | juick-www/src/main/resources/static/logo.png (renamed from juick-www/src/main/resources/logo.png) | bin | 1184 -> 1184 bytes | |||
-rw-r--r-- | juick-www/src/main/resources/static/tagscloud.png (renamed from juick-www/src/main/resources/tagscloud.png) | bin | 42316 -> 42316 bytes | |||
-rw-r--r-- | juick-www/src/main/resources/templates/layouts/content.html | 4 |
13 files changed, 9 insertions, 53 deletions
diff --git a/juick-www/src/main/js/killy/index.js b/juick-www/src/main/assets/embed.js index 25c37142..25c37142 100644 --- a/juick-www/src/main/js/killy/index.js +++ b/juick-www/src/main/assets/embed.js diff --git a/juick-www/src/main/static/logo.png b/juick-www/src/main/assets/logo.png Binary files differindex 4e0f6d56..4e0f6d56 100644 --- a/juick-www/src/main/static/logo.png +++ b/juick-www/src/main/assets/logo.png diff --git a/juick-www/src/main/static/logo@2x.png b/juick-www/src/main/assets/logo@2x.png Binary files differindex 6febeaf9..6febeaf9 100644 --- a/juick-www/src/main/static/logo@2x.png +++ b/juick-www/src/main/assets/logo@2x.png diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/assets/scripts.js index c6293266..9da9ce3c 100644 --- a/juick-www/src/main/static/scripts.js +++ b/juick-www/src/main/assets/scripts.js @@ -2,8 +2,8 @@ require('whatwg-fetch'); require('element-closest'); require('classlist.js'); require('url-search-params-polyfill'); -let killy = require('killy'); let Awesomplete = require('awesomplete'); +import * as killy from './embed'; if (!('remove' in Element.prototype)) { // Firefox <23 Element.prototype.remove = function() { diff --git a/juick-www/src/main/static/style.css b/juick-www/src/main/assets/style.css index ce80e650..ce80e650 100644 --- a/juick-www/src/main/static/style.css +++ b/juick-www/src/main/assets/style.css 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<String, String> manifest = jsonMapper.readValue(manifestString, - new TypeReference<HashMap<String, String>>() {}); - scriptsUrl = manifest.get("scripts.js"); - styleUrl = manifest.get("style.css"); - } + private ResourceUrlProvider resourceUrlProvider; public List<Tag> parseTags(String tagsStr) { List<Tag> 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"); } } diff --git a/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java b/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java index 19329dad..65871088 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WebSecurityConfig.java @@ -72,7 +72,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.addFilterAfter(hashParamAuthenticationFilter(), BasicAuthenticationFilter.class); http .authorizeRequests() - .antMatchers("/settings", "/pm/**", "/**/bl", "/_twitter", "/post", "/comment").authenticated() + .antMatchers("/settings", "/pm/**", "/**/bl", "/_twitter", "/post", "/comment") + .authenticated() .anyRequest().permitAll() .and() .anonymous().principal(JuickUser.ANONYMOUS_USER).authorities(JuickUser.ANONYMOUS_AUTHORITY) 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 9c35f1c2..34720c33 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 @@ -41,16 +41,11 @@ import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.core.Ordered; -import org.springframework.http.CacheControl; import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.resource.PathResourceResolver; import javax.inject.Inject; import java.util.Collections; -import java.util.concurrent.TimeUnit; /** * Created by aalexeev on 11/22/16. @@ -97,23 +92,6 @@ public class WwwAppConfiguration implements WebMvcConfigurer { public CloudflareCache cloudflareCache() { return new CloudflareCache(); } - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.setOrder(Ordered.HIGHEST_PRECEDENCE); - registry.addResourceHandler( - "/scripts*.js*", - "/style*.css*", - "/*.png", - "/favicon.ico") - .addResourceLocations("classpath:/") - .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()) - .resourceChain(true) - .addResolver(new PathResourceResolver()); - - registry.addResourceHandler("/static/**") - .addResourceLocations("/static/") - .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()); - } @Bean public Loader templateLoader() { return new ClasspathLoader(); diff --git a/juick-www/src/main/js/killy/package.json b/juick-www/src/main/js/killy/package.json deleted file mode 100644 index 1360826d..00000000 --- a/juick-www/src/main/js/killy/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "main": "../../src/main/js/killy/index.js", - "name": "killy", - "version": "0.0.1", - "private": true -}
\ No newline at end of file diff --git a/juick-www/src/main/resources/favicon.png b/juick-www/src/main/resources/static/favicon.png Binary files differindex bc7161e2..bc7161e2 100644 --- a/juick-www/src/main/resources/favicon.png +++ b/juick-www/src/main/resources/static/favicon.png diff --git a/juick-www/src/main/resources/logo.png b/juick-www/src/main/resources/static/logo.png Binary files differindex 933f6099..933f6099 100644 --- a/juick-www/src/main/resources/logo.png +++ b/juick-www/src/main/resources/static/logo.png diff --git a/juick-www/src/main/resources/tagscloud.png b/juick-www/src/main/resources/static/tagscloud.png Binary files differindex 3e1bf169..3e1bf169 100644 --- a/juick-www/src/main/resources/tagscloud.png +++ b/juick-www/src/main/resources/static/tagscloud.png diff --git a/juick-www/src/main/resources/templates/layouts/content.html b/juick-www/src/main/resources/templates/layouts/content.html index 4c283116..2ca9fd7e 100644 --- a/juick-www/src/main/resources/templates/layouts/content.html +++ b/juick-www/src/main/resources/templates/layouts/content.html @@ -3,8 +3,8 @@ <head id="org" itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization"> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> - <script type="text/javascript" src="/{{ beans.webApp.scriptsUrl }}"></script> - <link rel="stylesheet" type="text/css" href="/{{ beans.webApp.styleUrl }}"/> + <script type="text/javascript" src="{{ beans.webApp.scriptsUrl }}"></script> + <link rel="stylesheet" type="text/css" href="{{ beans.webApp.styleUrl }}"/> {% block headers %} {{ headers | default('') | raw }} {% endblock %} |