From 09d87962cf4b025431a0647fe889504b621292fd Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 19 Oct 2019 22:08:58 +0200 Subject: Better index.html handling in spring webflux --- .../kvision/remote/KVRouterConfiguration.kt | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'kvision-modules/kvision-server-spring-boot') diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVRouterConfiguration.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVRouterConfiguration.kt index 215848a7..42c4107d 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVRouterConfiguration.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVRouterConfiguration.kt @@ -21,21 +21,25 @@ */ package pl.treksoft.kvision.remote +import org.springframework.beans.factory.annotation.Value import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.core.io.Resource +import org.springframework.http.MediaType.TEXT_HTML import org.springframework.stereotype.Component -import org.springframework.web.reactive.function.server.RouterFunction import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.ServerResponse import org.springframework.web.reactive.function.server.buildAndAwait import org.springframework.web.reactive.function.server.coRouter import org.springframework.web.reactive.function.server.router -import java.net.URI @Configuration open class KVRouterConfiguration { + @Value("classpath:/public/index.html") + private lateinit var indexHtml: Resource + @Bean open fun kvRoutes(kvHandler: KVHandler) = coRouter { GET("/kv/**", kvHandler::handle) @@ -46,16 +50,9 @@ open class KVRouterConfiguration { } @Bean - open fun indexRouter(): RouterFunction { - val redirectToIndex = - ServerResponse - .temporaryRedirect(URI("/index.html")) - .build() - - return router { - GET("/") { - redirectToIndex - } + open fun indexRouter() = router { + GET("/") { + ok().contentType(TEXT_HTML).bodyValue(indexHtml) } } } -- cgit