mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
18.44.2021 6d56424f36c8eb2bdf2976fa405a8c3f544e1d44
borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/WebConfig.kt
@@ -4,10 +4,7 @@
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.ViewResolver
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.config.annotation.*
import org.springframework.web.servlet.view.InternalResourceViewResolver
@@ -16,23 +13,25 @@
@Configuration
@EnableWebMvc
open class WebConfig : WebMvcConfigurer {
    @Bean
    open fun internalResourceViewResolver(): ViewResolver {
        val bean = InternalResourceViewResolver()
        if (RunningMode.webBundled()) {
            bean.setPrefix("/webapp/")
        } else {
            bean.setPrefix("borgbutler-webapp/build/")
        }
        bean.setSuffix(".html")
        return bean
    }
    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        registry.addResourceHandler("/static/**")
            .addResourceLocations("/webapp/static/")
        registry.addResourceHandler("/**")
            .addResourceLocations("/webapp/")
        registry.addResourceHandler("/**").addResourceLocations(*CLASSPATH_RESOURCE_LOCATIONS);
    }
    @Bean
    open fun getViewResolver(): ViewResolver? {
        val resolver = InternalResourceViewResolver()
        resolver.setSuffix(".html")
        return resolver
    }
    override fun configurePathMatch(configurer: PathMatchConfigurer) {
        configurer.isUseTrailingSlashMatch = true
    }
    override fun addViewControllers(registry: ViewControllerRegistry) {
        registry.addViewController("/")
            .setViewName("forward:/index.html")
    }
    override fun addCorsMappings(registry: CorsRegistry) {
@@ -49,4 +48,8 @@
            registry.addMapping("/**")
        }
    }
    companion object {
        private val CLASSPATH_RESOURCE_LOCATIONS = arrayOf("classpath:/webapp/static/", "classpath:/webapp/")
    }
}