diff --git a/src/commonMain/kotlin/commands/cli/ServeCommand.kt b/src/commonMain/kotlin/commands/cli/ServeCommand.kt index 1c8732a..3fe66b2 100644 --- a/src/commonMain/kotlin/commands/cli/ServeCommand.kt +++ b/src/commonMain/kotlin/commands/cli/ServeCommand.kt @@ -17,6 +17,7 @@ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.plugins.cors.routing.CORS import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders import io.ktor.server.response.respond +import io.ktor.server.routing.Route import io.ktor.server.routing.get import io.ktor.server.routing.routing import kotlinx.coroutines.Runnable @@ -31,7 +32,7 @@ class ServeCommand( ) : Runnable { @Serializable - private data class MessageResponse(val message: String) + data class MessageResponse(val message: String) private lateinit var server: BaseApplicationEngine private lateinit var storedRepos: List @@ -86,7 +87,7 @@ class ServeCommand( install(ContentNegotiation) { json() } routing { - get("/") { call.respond(MessageResponse("Yep, it runs…")) } + setUpRoot() get("/repos") { call.respond(storedRepos) } get("/metrics") { call.respond(metricsByName) } get("/time-series") { call.respond(metricsByNameTimeSeries) } @@ -98,3 +99,5 @@ class ServeCommand( } } + +expect fun Route.setUpRoot(): Route diff --git a/src/jvmMain/kotlin/commands/cli/ServeCommand.kt b/src/jvmMain/kotlin/commands/cli/ServeCommand.kt new file mode 100644 index 0000000..9ec0303 --- /dev/null +++ b/src/jvmMain/kotlin/commands/cli/ServeCommand.kt @@ -0,0 +1,11 @@ +package commands.cli + +import io.ktor.server.http.content.singlePageApplication +import io.ktor.server.routing.Route + +actual fun Route.setUpRoot(): Route = apply { + singlePageApplication { + useResources = true + filesPath = "web" + } +} diff --git a/src/macNativeMain/kotlin/commands/cli/ServeCommand.kt b/src/macNativeMain/kotlin/commands/cli/ServeCommand.kt new file mode 100644 index 0000000..39cc10f --- /dev/null +++ b/src/macNativeMain/kotlin/commands/cli/ServeCommand.kt @@ -0,0 +1,11 @@ +package commands.cli + +import commands.cli.ServeCommand.MessageResponse +import io.ktor.server.application.call +import io.ktor.server.response.respond +import io.ktor.server.routing.Route +import io.ktor.server.routing.get + +actual fun Route.setUpRoot() = get("/") { + call.respond(MessageResponse("UI runs only on the JVM")) +}