aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-19 22:08:58 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-19 22:08:58 +0200
commit09d87962cf4b025431a0647fe889504b621292fd (patch)
tree9d7d2ebf876f1575f0ef5e8fece651b55a261984
parent95142ec0da1e3232d9c9419bebf663d4d3f0aad8 (diff)
downloadkvision-09d87962cf4b025431a0647fe889504b621292fd.tar.gz
kvision-09d87962cf4b025431a0647fe889504b621292fd.tar.bz2
kvision-09d87962cf4b025431a0647fe889504b621292fd.zip
Better index.html handling in spring webflux
-rw-r--r--kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVRouterConfiguration.kt21
1 files changed, 9 insertions, 12 deletions
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<ServerResponse> {
- val redirectToIndex =
- ServerResponse
- .temporaryRedirect(URI("/index.html"))
- .build()
-
- return router {
- GET("/") {
- redirectToIndex
- }
+ open fun indexRouter() = router {
+ GET("/") {
+ ok().contentType(TEXT_HTML).bodyValue(indexHtml)
}
}
}