Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Commit 199dc60

Browse files
committed
Reconfigure serve command to host web UI
1 parent 96f40a0 commit 199dc60

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/commonMain/kotlin/commands/cli/ServeCommand.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
1717
import io.ktor.server.plugins.cors.routing.CORS
1818
import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders
1919
import io.ktor.server.response.respond
20+
import io.ktor.server.routing.Route
2021
import io.ktor.server.routing.get
2122
import io.ktor.server.routing.routing
2223
import kotlinx.coroutines.Runnable
@@ -31,7 +32,7 @@ class ServeCommand(
3132
) : Runnable {
3233

3334
@Serializable
34-
private data class MessageResponse(val message: String)
35+
data class MessageResponse(val message: String)
3536

3637
private lateinit var server: BaseApplicationEngine
3738
private lateinit var storedRepos: List<Repository>
@@ -86,7 +87,7 @@ class ServeCommand(
8687
install(ContentNegotiation) { json() }
8788

8889
routing {
89-
get("/") { call.respond(MessageResponse("Yep, it runs…")) }
90+
setUpRoot()
9091
get("/repos") { call.respond(storedRepos) }
9192
get("/metrics") { call.respond(metricsByName) }
9293
get("/time-series") { call.respond(metricsByNameTimeSeries) }
@@ -98,3 +99,5 @@ class ServeCommand(
9899
}
99100

100101
}
102+
103+
expect fun Route.setUpRoot(): Route
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package commands.cli
2+
3+
import io.ktor.server.http.content.singlePageApplication
4+
import io.ktor.server.routing.Route
5+
6+
actual fun Route.setUpRoot(): Route = apply {
7+
singlePageApplication {
8+
useResources = true
9+
filesPath = "web"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package commands.cli
2+
3+
import commands.cli.ServeCommand.MessageResponse
4+
import io.ktor.server.application.call
5+
import io.ktor.server.response.respond
6+
import io.ktor.server.routing.Route
7+
import io.ktor.server.routing.get
8+
9+
actual fun Route.setUpRoot() = get("/") {
10+
call.respond(MessageResponse("UI runs only on the JVM"))
11+
}

0 commit comments

Comments
 (0)