From e54a4313b6d731733df3508f17f1e69593a53c53 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 6 Apr 2018 00:30:06 +0000 Subject: [PATCH] Merged in SHIBUI-443 (pull request #52) SHIBUI-443 --- backend/build.gradle | 3 +- .../StaticResourcesConfiguration.java | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/StaticResourcesConfiguration.java diff --git a/backend/build.gradle b/backend/build.gradle index cb756e24a..98b40151b 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -28,7 +28,8 @@ bootWar { attributes("Manifest-Version" : "1.0", "Implementation-Version" : "${project.version}") } from(tasks.findByPath(':ui:npm_run_buildProd').outputs) { - into '/' + // into '/' + into '/public' } archiveName = "${baseName}.war" } diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/StaticResourcesConfiguration.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/StaticResourcesConfiguration.java new file mode 100644 index 000000000..1c8a86907 --- /dev/null +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/StaticResourcesConfiguration.java @@ -0,0 +1,62 @@ +package edu.internet2.tier.shibboleth.admin.ui.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ResourceProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.resource.PathResourceResolver; + +import java.io.IOException; +import java.util.Arrays; + +/** + * class for helping angular work. inspired by https://blog.jdriven.com/2016/10/integrate-angular-spring-boot-gradle/ + */ + +@Configuration +@EnableConfigurationProperties({ResourceProperties.class}) +public class StaticResourcesConfiguration implements WebMvcConfigurer { + static final String[] STATIC_RESOURCES = new String[]{ + "/**/*.css", + "/**/*.html", + "/**/*.js", + "/**/*.json", + "/**/*.bmp", + "/**/*.jpeg", + "/**/*.jpg", + "/**/*.png", + "/**/*.ttf", + "/**/*.eot", + "/**/*.svg", + "/**/*.woff", + "/**/*.woff2" + }; + + @Autowired + private ResourceProperties resourceProperties = new ResourceProperties(); + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler(STATIC_RESOURCES) + .addResourceLocations(resourceProperties.getStaticLocations()) + .setCachePeriod(10); + registry.addResourceHandler("/**") + .addResourceLocations( + Arrays.stream(resourceProperties.getStaticLocations()) + .map(l -> l + "index.html") + .toArray(String[]::new) + ) + .setCachePeriod(10) + .resourceChain(true) + .addResolver(new PathResourceResolver() { + @Override + protected Resource getResource(String resourcePath, Resource location) throws IOException { + return location.exists() && location.isReadable() ? location : null; + } + } + ); + } +}