Compare commits

...

2 Commits

Author SHA1 Message Date
calboo
ccd5225c3b test route 2025-11-30 21:00:48 +01:00
calboo
8207d09703 dependency update 2025-11-30 20:25:35 +01:00
5 changed files with 142 additions and 12 deletions

View File

@@ -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"
@@ -11,6 +13,22 @@ repositories {
dependencies {
testImplementation(kotlin("test"))
// Ktor server dependencies
implementation("io.ktor:ktor-server-netty:2.3.4")
implementation("io.ktor:ktor-server-core:2.3.4")
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")
implementation("io.ktor:ktor-client-core:2.3.4")
implementation("io.ktor:ktor-client-cio:2.3.4")
implementation("io.ktor:ktor-client-content-negotiation:2.3.4")
}
tasks.test {
@@ -18,4 +36,24 @@ tasks.test {
}
kotlin {
jvmToolchain(23)
}
tasks.register<Jar>("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
}

View File

@@ -1,16 +1,16 @@
package org.calvin.erfmann
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() {
val name = "Kotlin"
//TIP Press <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
println("i = $i")
}
import org.calvin.erfmann.api.apiServ
val apiServ = apiServ()
fun main() {
apiServ.startServer()
}

View File

@@ -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(
)
}
}

View File

@@ -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()
}
}

View File

@@ -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"))
}
}
}