aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-jooby/src/main/kotlin/pl
diff options
context:
space:
mode:
Diffstat (limited to 'kvision-modules/kvision-server-jooby/src/main/kotlin/pl')
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt (renamed from kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt)22
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt19
2 files changed, 14 insertions, 27 deletions
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt
index eab093ec..9ae6d0e7 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt
@@ -27,21 +27,11 @@ import org.jooby.json.Jackson
import pl.treksoft.kvision.types.KV_JSON_DATE_FORMAT
import java.text.SimpleDateFormat
-/**
- * A Jooby based server.
- */
-open class KVServer(init: KVServer.() -> Unit) : Kooby() {
- init {
- @Suppress("LeakingThis")
- assets("/", "index.html")
- @Suppress("LeakingThis")
- assets("/**").onMissing(0)
- val mapper = jacksonObjectMapper().apply {
- dateFormat = SimpleDateFormat(KV_JSON_DATE_FORMAT)
- }
- @Suppress("LeakingThis")
- use(Jackson(mapper))
- @Suppress("LeakingThis")
- init.invoke(this)
+fun Kooby.kvisionInit() {
+ assets("/", "/assets/index.html")
+ assets("/**", "/assets/{0}").onMissing(0)
+ val mapper = jacksonObjectMapper().apply {
+ dateFormat = SimpleDateFormat(KV_JSON_DATE_FORMAT)
}
+ use(Jackson(mapper))
}
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
index 4e8516d3..bff27798 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt
@@ -26,6 +26,7 @@ import com.google.inject.Injector
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
+import org.jooby.Kooby
import org.jooby.Request
import org.jooby.Response
import org.slf4j.Logger
@@ -44,7 +45,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name)
}
- protected val routes: MutableList<KVServer.() -> Unit> = mutableListOf()
+ val routes: MutableList<Kooby.() -> Unit> = mutableListOf()
val mapper = jacksonObjectMapper().apply {
dateFormat = SimpleDateFormat(KV_JSON_DATE_FORMAT)
}
@@ -349,7 +350,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
method: RpcHttpMethod,
path: String,
handler: (Request, Response) -> Unit
- ): KVServer.() -> Unit {
+ ): Kooby.() -> Unit {
return {
when (method) {
RpcHttpMethod.POST -> post(path, handler)
@@ -370,14 +371,10 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
} ?: null as T
}
- /**
- * Applies all defined routes to the given server.
- * @param k a server
- */
- fun applyRoutes(k: KVServer) {
- routes.forEach {
- it.invoke(k)
- }
- }
+}
+fun <T : Any> Kooby.applyRoutes(serviceManager: KVServiceManager<T>) {
+ serviceManager.routes.forEach {
+ it.invoke(this@applyRoutes)
+ }
}