-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in SHIBUI-443 (pull request #52)
SHIBUI-443
- Loading branch information
Jonathan Johnson
committed
Apr 6, 2018
1 parent
abf83e7
commit e54a431
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...va/edu/internet2/tier/shibboleth/admin/ui/configuration/StaticResourcesConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
); | ||
} | ||
} |