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 | |
parent | cc551432bf80e4466b92c42a77a094f31408abeb (diff) |
www: spring boot autoconfigured static resources
+ cache busting using Spring
17 files changed, 21 insertions, 108 deletions
diff --git a/juick-common/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/juick-common/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index ff34e370..1c520303 100644 --- a/juick-common/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/juick-common/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -36,6 +36,8 @@ import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; +import org.springframework.web.servlet.resource.ResourceUrlProvider; import rocks.xmpp.core.session.Extension; import rocks.xmpp.core.session.XmppSessionConfiguration; import rocks.xmpp.core.session.debug.LogbackDebugger; @@ -57,12 +59,10 @@ public class BaseWebConfiguration implements WebMvcConfigurer, SchedulingConfigu configurer.setUseSuffixPatternMatch(false); } - @Override - public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(jsonMapper()); - converters.add(converter); + @Bean + public ResourceUrlEncodingFilter resourceUrlEncodingFilter() { + return new ResourceUrlEncodingFilter(); } - @Bean public ObjectMapper jsonMapper() { ObjectMapper mapper = new ObjectMapper(); diff --git a/juick-www/package.json b/juick-www/package.json index e2aaa992..512b4f2f 100644 --- a/juick-www/package.json +++ b/juick-www/package.json @@ -15,7 +15,6 @@ "babel-core": "^6.26.0", "babel-loader": "^7.1.4", "babel-preset-env": "^1.6.1", - "clean-webpack-plugin": "^0.1.19", "css-loader": "^0.28.11", "eslint": "^4.19.0", "eslint-loader": "^2.0.0", @@ -31,7 +30,6 @@ "uglify-loader": "^2.0.0", "url-loader": "^1.0.1", "webpack": "^4.2.0", - "webpack-asset-pipeline": "^1.1.1", "webpack-cli": "^2.0.12" }, "dependencies": { @@ -39,7 +37,6 @@ "classlist.js": "^1.1.20150312", "element-closest": "^2.0.2", "evil-icons": "^1.9.0", - "killy": "file:src/main/js/killy", "url-search-params-polyfill": "^3.0.0", "whatwg-fetch": "^2.0.3" } 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 %} diff --git a/juick-www/webpack.config.js b/juick-www/webpack.config.js index c23524b0..a56c1b74 100644 --- a/juick-www/webpack.config.js +++ b/juick-www/webpack.config.js @@ -1,25 +1,23 @@ var webpack = require("webpack") var ExtractTextPlugin = require("extract-text-webpack-plugin") var StyleLintPlugin = require('stylelint-webpack-plugin') -var AssetPipelinePlugin = require('webpack-asset-pipeline') -var CleanWebpackPlugin = require('clean-webpack-plugin') module.exports = { devtool: 'source-map', entry: { "scripts" : [ - __dirname + "/src/main/static/scripts.js", + __dirname + "/src/main/assets/scripts.js", require.resolve('evil-icons/assets/evil-icons.js') ], "style" : [ - __dirname + "/src/main/static/style.css", + __dirname + "/src/main/assets/style.css", require.resolve('evil-icons/assets/evil-icons.css'), require.resolve('awesomplete/awesomplete.css') ] }, output: { - path: __dirname + "/src/main/resources", - filename: "[name].[hash].js" + path: __dirname + "/src/main/resources/static", + filename: "[name].js" }, module: { rules: [ @@ -31,11 +29,8 @@ module.exports = { ] }, plugins: [ - new CleanWebpackPlugin([ '*.css', '*.js', '*.map' ], { root: __dirname + '/src/main/resources' }), - new webpack.optimize.ModuleConcatenationPlugin(), - new StyleLintPlugin({ configFile: '.stylelintrc.json', context: 'src/main/static', files: ['**/*.css'], emitErrors: false }), - new ExtractTextPlugin({ filename: "style.[hash].css", allChunks: true }), - new AssetPipelinePlugin() + new StyleLintPlugin({ configFile: '.stylelintrc.json', context: 'src/main/assets', files: ['**/*.css'], emitErrors: false }), + new ExtractTextPlugin({ filename: "style.css", allChunks: true }) ], } diff --git a/juick-www/yarn.lock b/juick-www/yarn.lock index f580308d..c3998328 100644 --- a/juick-www/yarn.lock +++ b/juick-www/yarn.lock @@ -1338,12 +1338,6 @@ classlist.js@^1.1.20150312: version "1.1.20150312" resolved "https://registry.yarnpkg.com/classlist.js/-/classlist.js-1.1.20150312.tgz#1d70842f7022f08d9ac086ce69e5b250f2c57789" -clean-webpack-plugin@^0.1.19: - version "0.1.19" - resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-0.1.19.tgz#ceda8bb96b00fe168e9b080272960d20fdcadd6d" - dependencies: - rimraf "^2.6.1" - cli-cursor@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987" @@ -2428,14 +2422,6 @@ from2@^2.1.0, from2@^2.1.1: inherits "^2.0.1" readable-stream "^2.0.0" -fs-extra@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950" - dependencies: - graceful-fs "^4.1.2" - jsonfile "^2.1.0" - klaw "^1.0.0" - fs-write-stream-atomic@^1.0.8: version "1.0.10" resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9" @@ -2692,7 +2678,7 @@ got@^8.2.0: url-parse-lax "^3.0.0" url-to-options "^1.0.1" -graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.1.11, graceful-fs@^4.1.2: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -3426,12 +3412,6 @@ json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" -jsonfile@^2.1.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" - optionalDependencies: - graceful-fs "^4.1.6" - jsonify@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" @@ -3451,9 +3431,6 @@ keyv@3.0.0: dependencies: json-buffer "3.0.0" -"killy@file:src/main/js/killy": - version "0.0.1" - kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: version "3.2.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" @@ -3474,12 +3451,6 @@ kind-of@^6.0.0, kind-of@^6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" -klaw@^1.0.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" - optionalDependencies: - graceful-fs "^4.1.9" - known-css-properties@^0.6.0: version "0.6.1" resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.6.1.tgz#31b5123ad03d8d1a3f36bd4155459c981173478b" @@ -6233,12 +6204,6 @@ webpack-addons@^1.1.5: dependencies: jscodeshift "^0.4.0" -webpack-asset-pipeline@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/webpack-asset-pipeline/-/webpack-asset-pipeline-1.1.1.tgz#3e94cff5adbc1f20c4f5b51821d5912dff787991" - dependencies: - fs-extra "^1.0.0" - webpack-cli@^2.0.12: version "2.0.12" resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-2.0.12.tgz#64db876d044f03d8d6544281854b71a3a3c77dd3" |