Addressing https://github.com/hapifhir/hapi-fhir-jpaserver-starter/issues/486 and https://github.com/hapifhir/hapi-fhir-jpaserver-starter/issues/485
This commit is contained in:
@@ -76,6 +76,8 @@ public class AppProperties {
|
|||||||
|
|
||||||
private String staticLocation = null;
|
private String staticLocation = null;
|
||||||
|
|
||||||
|
private String staticLocationPrefix = "/static";
|
||||||
|
|
||||||
private Boolean lastn_enabled = false;
|
private Boolean lastn_enabled = false;
|
||||||
private boolean store_resource_in_lucene_index_enabled = false;
|
private boolean store_resource_in_lucene_index_enabled = false;
|
||||||
private NormalizedQuantitySearchLevel normalized_quantity_search_level = NormalizedQuantitySearchLevel.NORMALIZED_QUANTITY_SEARCH_NOT_SUPPORTED;
|
private NormalizedQuantitySearchLevel normalized_quantity_search_level = NormalizedQuantitySearchLevel.NORMALIZED_QUANTITY_SEARCH_NOT_SUPPORTED;
|
||||||
@@ -89,6 +91,15 @@ public class AppProperties {
|
|||||||
|
|
||||||
private final List<String> custom_interceptor_classes = new ArrayList<>();
|
private final List<String> custom_interceptor_classes = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getStaticLocationPrefix() {
|
||||||
|
return staticLocationPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStaticLocationPrefix(String staticLocationPrefix) {
|
||||||
|
this.staticLocationPrefix = staticLocationPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getCustomInterceptorClasses() {
|
public List<String> getCustomInterceptorClasses() {
|
||||||
return custom_interceptor_classes;
|
return custom_interceptor_classes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ca.uhn.fhir.jpa.starter;
|
package ca.uhn.fhir.jpa.starter;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@@ -14,25 +13,37 @@ import java.net.URI;
|
|||||||
@ConditionalOnProperty(prefix = "hapi.fhir", name = "staticLocation")
|
@ConditionalOnProperty(prefix = "hapi.fhir", name = "staticLocation")
|
||||||
public class ExtraStaticFilesConfigurer implements WebMvcConfigurer {
|
public class ExtraStaticFilesConfigurer implements WebMvcConfigurer {
|
||||||
|
|
||||||
public static final String ROOT_CONTEXT_PATH = "/static";
|
private String staticLocation;
|
||||||
@Autowired
|
private String rootContextPath;
|
||||||
AppProperties appProperties;
|
|
||||||
|
public ExtraStaticFilesConfigurer(AppProperties appProperties) {
|
||||||
|
|
||||||
|
rootContextPath = appProperties.getStaticLocationPrefix();
|
||||||
|
if(rootContextPath.endsWith("/"))
|
||||||
|
rootContextPath = rootContextPath.substring(0, rootContextPath.lastIndexOf('/'));
|
||||||
|
|
||||||
|
staticLocation = appProperties.getStaticLocation();
|
||||||
|
if(staticLocation.endsWith("/"))
|
||||||
|
staticLocation = staticLocation.substring(0, staticLocation.lastIndexOf('/'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry theRegistry) {
|
public void addResourceHandlers(ResourceHandlerRegistry theRegistry) {
|
||||||
theRegistry.addResourceHandler(ROOT_CONTEXT_PATH + "/**").addResourceLocations(appProperties.getStaticLocation());
|
theRegistry.addResourceHandler(rootContextPath + "/**").addResourceLocations(staticLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
String path = URI.create(appProperties.getStaticLocation()).getPath();
|
String path = URI.create(staticLocation).getPath();
|
||||||
String lastSegment = path.substring(path.lastIndexOf('/') + 1);
|
String lastSegment = path.substring(path.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
registry.addViewController(ROOT_CONTEXT_PATH).setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
registry.addViewController(rootContextPath).setViewName("redirect:" + rootContextPath + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
registry.addViewController(ROOT_CONTEXT_PATH + "/*").setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
registry.addViewController(rootContextPath + "/*").setViewName("redirect:" + rootContextPath + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
registry.addViewController(ROOT_CONTEXT_PATH + "/" + lastSegment + "/").setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
registry.addViewController(rootContextPath + "/" + lastSegment + "/").setViewName("redirect:" + rootContextPath + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ hapi:
|
|||||||
### forces the use of the https:// protocol for the returned server address.
|
### forces the use of the https:// protocol for the returned server address.
|
||||||
### alternatively, it may be set using the X-Forwarded-Proto header.
|
### alternatively, it may be set using the X-Forwarded-Proto header.
|
||||||
# use_apache_address_strategy_https: false
|
# use_apache_address_strategy_https: false
|
||||||
### enables the server to host content like HTML, css, etc. under the url pattern of /static/**
|
### enables the server to host content like HTML, css, etc. under the url pattern of eg. /static/**
|
||||||
|
# staticLocationPrefix: /static
|
||||||
### the deepest folder level will be used. E.g. - if you put file:/foo/bar/bazz as value then the files are resolved under /static/bazz/**
|
### the deepest folder level will be used. E.g. - if you put file:/foo/bar/bazz as value then the files are resolved under /static/bazz/**
|
||||||
#staticLocation: file:/foo/bar/bazz
|
#staticLocation: file:/foo/bar/bazz
|
||||||
### enable to set the Server URL
|
### enable to set the Server URL
|
||||||
|
|||||||
Reference in New Issue
Block a user