aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/configuration
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-20 15:16:08 +0300
committerGravatar Vitaly Takmazov2018-11-20 15:16:23 +0300
commitb0cfa955c77c4e36bd334324d0ccb2ff24ff549f (patch)
treec40954b3c453c7138514d1439fdcd6d969af0bec /src/main/java/com/juick/server/configuration
parent152efe1f31e1e568272fc401a3a19f2c6f7c9c49 (diff)
versioned avatars in www
Diffstat (limited to 'src/main/java/com/juick/server/configuration')
-rw-r--r--src/main/java/com/juick/server/configuration/WwwAppConfiguration.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
index 534154af..2286165d 100644
--- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
+++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
@@ -43,6 +43,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import javax.inject.Inject;
+import java.net.MalformedURLException;
+import java.nio.file.Paths;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
@@ -56,7 +58,7 @@ public class WwwAppConfiguration implements WebMvcConfigurer {
private UserService userService;
@Inject
private TagService tagService;
- @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: 'file:/tmp/'}}")
+ @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
private String avatarsPath;
@Bean
public CaffeineCacheManager cacheManager() {
@@ -126,11 +128,15 @@ public class WwwAppConfiguration implements WebMvcConfigurer {
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry
- .addResourceHandler("/**", "/i/a/**")
- .addResourceLocations("classpath:/static/", avatarsPath)
- .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
- .resourceChain(false)
- .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**"));
+ try {
+ registry
+ .addResourceHandler("/**", "/i/a/**")
+ .addResourceLocations("classpath:/static/", Paths.get(avatarsPath, "/a/").toUri().toURL().toString())
+ .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
+ .resourceChain(false)
+ .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**"));
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
}
}