test route
This commit is contained in:
@@ -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")
|
||||
@@ -32,3 +37,23 @@ 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
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
51
Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt
Normal file
51
Server/FastKeyValueServer/src/main/kotlin/api/apiServ.kt
Normal 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(
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user