Skip to content

Commit

Permalink
Merged in SHIBUI-443 (pull request #52)
Browse files Browse the repository at this point in the history
SHIBUI-443
  • Loading branch information
Jonathan Johnson committed Apr 6, 2018
1 parent abf83e7 commit e54a431
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
);
}
}

0 comments on commit e54a431

Please sign in to comment.