From daefe6c26d199b969d6349af351e891fe301e673 Mon Sep 17 00:00:00 2001 From: ulfrxdev Date: Fri, 24 Apr 2026 18:22:37 +0200 Subject: [PATCH] refactor(01-05): rewrite Application.kt with ContentNegotiation, Flyway boot, /health MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove wildcard Ktor imports (D-11 allWarningsAsErrors safety) — all imports explicit - Install ContentNegotiation { json() } for @Serializable response bodies - Call Database.migrate(this) at boot — fails loudly if Postgres unreachable - Extract configureRouting() extension so tests can compose routing without DB - Replace template root greeting with GET /health → {"status":"ok"} (D-16) - main() shape unchanged: embeddedServer(Netty, SERVER_PORT, "0.0.0.0", ...) --- .../kotlin/dev/ulfrx/recipe/Application.kt | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/server/src/main/kotlin/dev/ulfrx/recipe/Application.kt b/server/src/main/kotlin/dev/ulfrx/recipe/Application.kt index daab354..8687ae3 100644 --- a/server/src/main/kotlin/dev/ulfrx/recipe/Application.kt +++ b/server/src/main/kotlin/dev/ulfrx/recipe/Application.kt @@ -1,20 +1,36 @@ package dev.ulfrx.recipe -import io.ktor.server.application.* -import io.ktor.server.engine.* -import io.ktor.server.netty.* -import io.ktor.server.response.* -import io.ktor.server.routing.* +import io.ktor.serialization.kotlinx.json.json +import io.ktor.server.application.Application +import io.ktor.server.application.install +import io.ktor.server.engine.embeddedServer +import io.ktor.server.netty.Netty +import io.ktor.server.plugins.contentnegotiation.ContentNegotiation +import io.ktor.server.response.respond +import io.ktor.server.routing.get +import io.ktor.server.routing.routing +import kotlinx.serialization.Serializable fun main() { embeddedServer(Netty, port = SERVER_PORT, host = "0.0.0.0", module = Application::module) .start(wait = true) } +@Serializable +private data class Health(val status: String) + fun Application.module() { + install(ContentNegotiation) { + json() + } + Database.migrate(this) + configureRouting() +} + +fun Application.configureRouting() { routing { - get("/") { - call.respondText("Ktor: ${Greeting().greet()}") + get("/health") { + call.respond(Health(status = "ok")) } } -} \ No newline at end of file +}