Feature/index default (#475)
* Added default * Refactored the default resolution
This commit is contained in:
committed by
GitHub
parent
f3493c7026
commit
07d9a193d2
@@ -3,20 +3,38 @@ package ca.uhn.fhir.jpa.starter;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@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";
|
||||||
@Autowired
|
@Autowired
|
||||||
AppProperties appProperties;
|
AppProperties appProperties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry theRegistry) {
|
public void addResourceHandlers(ResourceHandlerRegistry theRegistry) {
|
||||||
theRegistry
|
theRegistry.addResourceHandler(ROOT_CONTEXT_PATH + "/**").addResourceLocations(appProperties.getStaticLocation());
|
||||||
.addResourceHandler("/static/**")
|
|
||||||
.addResourceLocations(appProperties.getStaticLocation());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
|
String path = URI.create(appProperties.getStaticLocation()).getPath();
|
||||||
|
String lastSegment = path.substring(path.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
|
registry.addViewController(ROOT_CONTEXT_PATH).setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
|
registry.addViewController(ROOT_CONTEXT_PATH + "/*").setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
|
registry.addViewController(ROOT_CONTEXT_PATH + "/" + lastSegment + "/").setViewName("redirect:" + ROOT_CONTEXT_PATH + "/" + lastSegment + "/index.html");
|
||||||
|
|
||||||
|
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,8 @@ hapi:
|
|||||||
### 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 /static/**
|
||||||
# staticLocation: file:/usr/somewhere/
|
### 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
|
||||||
### enable to set the Server URL
|
### enable to set the Server URL
|
||||||
# server_address: http://hapi.fhir.org/baseR4
|
# server_address: http://hapi.fhir.org/baseR4
|
||||||
# defer_indexing_for_codesystems_of_size: 101
|
# defer_indexing_for_codesystems_of_size: 101
|
||||||
|
|||||||
Reference in New Issue
Block a user