From ccd5225c3bbfaea47942e7e5173a64f4ae0e44c0 Mon Sep 17 00:00:00 2001 From: calboo Date: Sun, 30 Nov 2025 21:00:48 +0100 Subject: [PATCH] test route --- Server/FastKeyValueServer/build.gradle.kts | 25 +++++++++ .../src/main/kotlin/Main.kt | 24 ++++----- .../src/main/kotlin/api/apiServ.kt | 51 +++++++++++++++++++ .../src/main/kotlin/api/plugins/Routing.kt | 23 +++++++++ .../src/main/kotlin/api/routes/helloRoute.kt | 18 +++++++ 5 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt create mode 100644 Server/FastKeyValueServer/src/main/kotlin/api/plugins/Routing.kt create mode 100644 Server/FastKeyValueServer/src/main/kotlin/api/routes/helloRoute.kt diff --git a/Server/FastKeyValueServer/build.gradle.kts b/Server/FastKeyValueServer/build.gradle.kts index 76810f1..622e943 100644 --- a/Server/FastKeyValueServer/build.gradle.kts +++ b/Server/FastKeyValueServer/build.gradle.kts @@ -1,5 +1,7 @@ plugins { kotlin("jvm") version "2.1.20" + id("io.ktor.plugin") version "2.3.4" + kotlin("plugin.serialization") version "1.9.0" } group = "org.calvin.erfmann" @@ -18,6 +20,9 @@ dependencies { implementation("io.ktor:ktor-server-content-negotiation:2.3.4") implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.4") + //Logging + implementation("ch.qos.logback:logback-classic:1.5.13") + //Ktor Websockets and CORS implementation("io.ktor:ktor-server-websockets:2.3.4") implementation("io.ktor:ktor-server-cors:2.3.4") @@ -31,4 +36,24 @@ tasks.test { } kotlin { jvmToolchain(23) +} + +tasks.register("fatJar") { + group = "build" + description = "Assemble a fat jar with all dependencies." + + archiveClassifier.set("all") + + manifest { + attributes["Main-Class"] = "MainKt" // ggf. anpassen auf dein Main Package + } + + from(sourceSets.main.get().output) + + dependsOn(configurations.runtimeClasspath) + from({ + configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) } + }) + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE } \ No newline at end of file diff --git a/Server/FastKeyValueServer/src/main/kotlin/Main.kt b/Server/FastKeyValueServer/src/main/kotlin/Main.kt index 72e95c5..a762ec5 100644 --- a/Server/FastKeyValueServer/src/main/kotlin/Main.kt +++ b/Server/FastKeyValueServer/src/main/kotlin/Main.kt @@ -1,16 +1,16 @@ package org.calvin.erfmann -//TIP To Run code, press or -// click the icon in the gutter. -fun main() { - val name = "Kotlin" - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - println("Hello, " + name + "!") - for (i in 1..5) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - println("i = $i") - } + + +import org.calvin.erfmann.api.apiServ + +val apiServ = apiServ() + +fun main() { + + + + apiServ.startServer() + } \ No newline at end of file diff --git a/Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt b/Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt new file mode 100644 index 0000000..5c9e0d0 --- /dev/null +++ b/Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt @@ -0,0 +1,51 @@ +package org.calvin.erfmann.api + +import io.ktor.client.HttpClient +import io.ktor.client.HttpClientConfig +import io.ktor.client.engine.cio.CIO +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +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.websocket.WebSockets +import io.ktor.server.websocket.pingPeriod +import io.ktor.server.websocket.timeout +import kotlinx.serialization.json.Json +import org.calvin.erfmann.api.plugins.configureRouting +import java.time.Duration + +class apiServ { + + + + + + + + + + + fun startServer(){ + embeddedServer(Netty, port = 9000, host = "0.0.0.0") { + module() + }.start(wait = true) + } + + fun Application.module() { + install(ContentNegotiation) { // SERVER Plugin mit Alias + json() + } + install(WebSockets.Plugin) { + pingPeriod = Duration.ofSeconds(15) + timeout = Duration.ofSeconds(30) + maxFrameSize = Long.MAX_VALUE + masking = false + } + configureRouting( + + ) + } +} \ No newline at end of file diff --git a/Server/FastKeyValueServer/src/main/kotlin/api/plugins/Routing.kt b/Server/FastKeyValueServer/src/main/kotlin/api/plugins/Routing.kt new file mode 100644 index 0000000..987521d --- /dev/null +++ b/Server/FastKeyValueServer/src/main/kotlin/api/plugins/Routing.kt @@ -0,0 +1,23 @@ +package org.calvin.erfmann.api.plugins + + + +import io.ktor.client.HttpClient +import io.ktor.client.engine.cio.CIO +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.serialization.kotlinx.json.json +import io.ktor.server.application.Application +import io.ktor.server.plugins.contentnegotiation.ContentNegotiation +import io.ktor.server.routing.routing +import kotlinx.serialization.json.Json +import org.calvin.erfmann.api.routes.helloRoutes + +fun Application.configureRouting() { + + routing { + helloRoutes() + + } +} + + diff --git a/Server/FastKeyValueServer/src/main/kotlin/api/routes/helloRoute.kt b/Server/FastKeyValueServer/src/main/kotlin/api/routes/helloRoute.kt new file mode 100644 index 0000000..89c7608 --- /dev/null +++ b/Server/FastKeyValueServer/src/main/kotlin/api/routes/helloRoute.kt @@ -0,0 +1,18 @@ +package org.calvin.erfmann.api.routes + +import io.ktor.server.application.call +import io.ktor.server.response.respond +import io.ktor.server.routing.Route +import io.ktor.server.routing.get +import io.ktor.server.routing.route + +fun Route.helloRoutes() { + route("/hello") { + + + get { + + call.respond(mapOf("message" to "hallo du knecht")) + } + } +} \ No newline at end of file