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

Kai Reinhard
18.06.2021 e2ddee8dd155f76dbb8326dae7d887bbe7492bcb
React reload works now: redirect to index.htlm
1 files modified
12 ■■■■ changed files
borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/WebConfig.kt 12 ●●●● patch | view | raw | blame | history
borgbutler-server/src/main/kotlin/de/micromata/borgbutler/server/WebConfig.kt
@@ -6,9 +6,7 @@
import org.springframework.web.servlet.ViewResolver
import org.springframework.web.servlet.config.annotation.*
import org.springframework.web.servlet.view.InternalResourceViewResolver
import java.io.File
import java.nio.file.Paths
import kotlin.io.path.Path
private val log = KotlinLogging.logger {}
@@ -42,8 +40,18 @@
    }
    override fun addViewControllers(registry: ViewControllerRegistry) {
        // https://stackoverflow.com/questions/39331929/spring-catch-all-route-for-index-html
        registry.addViewController("/")
            .setViewName("forward:/index.html")
        // Map "/word", "/word/word", and "/word/word/word" - except for anything starting with "/api/..." or ending with
        // a file extension like ".js" - to index.html. By doing this, the client receives and routes the url. It also
        // allows client-side URLs to be bookmarked.
        // Single directory level - no need to exclude "rest" (api)
        registry.addViewController("/{x:[\\w\\-]+}")
            .setViewName("forward:/index.html")
        // Multi-level directory path, need to exclude "rest" on the first part of the path
        registry.addViewController("/{x:^(?!rest$).*$}/**/{y:[\\w\\-]+}")
            .setViewName("forward:/index.html")
    }
    override fun addCorsMappings(registry: CorsRegistry) {