From c42943f8a9b2f0d350c42d30731574be7aac4b66 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 26 Mar 2018 11:42:42 +0300 Subject: www: cleanup configuration --- .../www/configuration/WwwAppConfiguration.java | 61 +++++++++++- .../www/configuration/WwwServletConfiguration.java | 102 --------------------- 2 files changed, 60 insertions(+), 103 deletions(-) delete mode 100644 juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java (limited to 'juick-www/src/main/java/com/juick') 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 5e6a0d0e..9c35f1c2 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 @@ -25,6 +25,13 @@ import com.juick.service.CloudflareCache; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.www.HelpService; +import com.mitchellbosecke.pebble.PebbleEngine; +import com.mitchellbosecke.pebble.extension.FormatterExtension; +import com.mitchellbosecke.pebble.loader.ClasspathLoader; +import com.mitchellbosecke.pebble.loader.Loader; +import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; +import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; +import org.apache.commons.codec.CharEncoding; import org.commonmark.ext.autolink.AutolinkExtension; import org.commonmark.node.Link; import org.commonmark.parser.Parser; @@ -34,17 +41,23 @@ 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. */ @Configuration @EnableCaching -@Import({WwwServletConfiguration.class, BaseWebConfiguration.class, WebSecurityConfig.class, SapeConfiguration.class, SearchConfiguration.class, +@Import({ BaseWebConfiguration.class, WebSecurityConfig.class, SapeConfiguration.class, SearchConfiguration.class, DataConfiguration.class, StorageConfiguration.class, XMPPConfiguration.class}) public class WwwAppConfiguration implements WebMvcConfigurer { @Inject @@ -84,5 +97,51 @@ 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(); + } + + @Bean + public SpringExtension springExtension() { + return new SpringExtension(); + } + + @Bean + public PebbleEngine pebbleEngine() { + return new PebbleEngine.Builder() + .loader(this.templateLoader()) + .extension(springExtension()) + .extension(new FormatterExtension()) + .strictVariables(true) + .build(); + } + + @Bean + public ViewResolver viewResolver() { + PebbleViewResolver viewResolver = new PebbleViewResolver(); + viewResolver.setPrefix("templates"); + viewResolver.setSuffix(".html"); + viewResolver.setPebbleEngine(pebbleEngine()); + viewResolver.setCharacterEncoding(CharEncoding.UTF_8); + return viewResolver; + } } 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 deleted file mode 100644 index a8dbad8b..00000000 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.juick.www.configuration; - -import com.juick.server.configuration.BaseWebConfiguration; -import com.mitchellbosecke.pebble.PebbleEngine; -import com.mitchellbosecke.pebble.extension.FormatterExtension; -import com.mitchellbosecke.pebble.loader.ClasspathLoader; -import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; -import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; -import org.apache.commons.codec.CharEncoding; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.http.CacheControl; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.resource.PathResourceResolver; - -import javax.inject.Inject; -import javax.servlet.ServletContext; -import java.util.concurrent.TimeUnit; - -/** - * Created by vitalyster on 28.06.2016. - */ -@Configuration -@ComponentScan(basePackages = {"com.juick.www"}) -@EnableWebMvc -public class WwwServletConfiguration extends BaseWebConfiguration { - - @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()); - } - @Override - public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { - configurer.enable(); - } - - @Bean - public Loader templateLoader() { - return new ClasspathLoader(); - } - - @Bean - public SpringExtension springExtension() { - return new SpringExtension(); - } - - @Bean - public PebbleEngine pebbleEngine() { - return new PebbleEngine.Builder() - .loader(this.templateLoader()) - .extension(springExtension()) - .extension(new FormatterExtension()) - .strictVariables(true) - .build(); - } - - @Bean - public ViewResolver viewResolver() { - PebbleViewResolver viewResolver = new PebbleViewResolver(); - viewResolver.setPrefix("templates"); - viewResolver.setSuffix(".html"); - viewResolver.setPebbleEngine(pebbleEngine()); - viewResolver.setCharacterEncoding(CharEncoding.UTF_8); - return viewResolver; - } -} -- cgit v1.2.3