-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03bfde9
commit 6712e84
Showing
9 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
plugins { | ||
id("Entropy.kotlin-common-conventions") | ||
id("com.ncorti.ktfmt.gradle") version "0.15.1" | ||
id("io.ktor.plugin") version "2.3.12" | ||
application | ||
} | ||
|
||
ktfmt { kotlinLangStyle() } | ||
|
||
dependencies { | ||
implementation(project(":core")) | ||
implementation("io.ktor:ktor-server-core-jvm") | ||
implementation("io.ktor:ktor-server-content-negotiation-jvm") | ||
implementation("io.ktor:ktor-serialization-jackson-jvm") | ||
implementation("io.ktor:ktor-server-call-logging-jvm") | ||
implementation("io.ktor:ktor-server-call-id-jvm") | ||
implementation("io.ktor:ktor-server-host-common-jvm") | ||
implementation("io.ktor:ktor-server-status-pages-jvm") | ||
implementation("io.ktor:ktor-server-sessions-jvm") | ||
implementation("io.ktor:ktor-server-netty-jvm") | ||
implementation("io.ktor:ktor-server-config-yaml") | ||
testImplementation("io.ktor:ktor-server-test-host-jvm") | ||
testImplementation(project(":test-core")) | ||
} | ||
|
||
application { | ||
// Define the main class for the application. | ||
mainClass.set("server.EntropyServer") | ||
mainClass.set("io.ktor.server.netty.EngineMain") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kotlin.code.style=official | ||
ktor_version=2.3.12 | ||
kotlin_version=2.0.20 | ||
logback_version=1.4.14 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import plugins.* | ||
import io.ktor.server.application.* | ||
import server.EntropyServer | ||
|
||
fun main(args: Array<String>) { | ||
io.ktor.server.netty.EngineMain.main(args) | ||
} | ||
|
||
fun Application.module() { | ||
configureSerialization() | ||
configureMonitoring() | ||
configureSecurity() | ||
configureRouting() | ||
|
||
// Boot old stuff | ||
EntropyServer.main(emptyArray()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package plugins | ||
|
||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.plugins.callid.* | ||
import io.ktor.server.plugins.callloging.* | ||
import io.ktor.server.request.* | ||
import org.slf4j.event.* | ||
|
||
fun Application.configureMonitoring() { | ||
install(CallLogging) { | ||
level = Level.INFO | ||
filter { call -> call.request.path().startsWith("/") } | ||
callIdMdc("call-id") | ||
} | ||
install(CallId) { | ||
header(HttpHeaders.XRequestId) | ||
verify { callId: String -> | ||
callId.isNotEmpty() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package plugins | ||
|
||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.plugins.statuspages.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
|
||
fun Application.configureRouting() { | ||
install(StatusPages) { | ||
exception<Throwable> { call, cause -> | ||
call.respondText(text = "500: $cause" , status = HttpStatusCode.InternalServerError) | ||
} | ||
} | ||
routing { | ||
get("/") { | ||
call.respondText("Hello World!") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package plugins | ||
|
||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import io.ktor.server.sessions.* | ||
|
||
fun Application.configureSecurity() { | ||
data class MySession(val count: Int = 0) | ||
install(Sessions) { | ||
cookie<MySession>("MY_SESSION") { | ||
cookie.extensions["SameSite"] = "lax" | ||
} | ||
} | ||
routing { | ||
get("/session/increment") { | ||
val session = call.sessions.get<MySession>() ?: MySession() | ||
call.sessions.set(session.copy(count = session.count + 1)) | ||
call.respondText("Counter is ${session.count}. Refresh to increment.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package plugins | ||
|
||
import com.fasterxml.jackson.databind.* | ||
import io.ktor.serialization.jackson.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.plugins.contentnegotiation.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
|
||
fun Application.configureSerialization() { | ||
install(ContentNegotiation) { | ||
jackson { | ||
enable(SerializationFeature.INDENT_OUTPUT) | ||
} | ||
} | ||
routing { | ||
get("/json/jackson") { | ||
call.respond(mapOf("hello" to "world")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ktor: | ||
application: | ||
modules: | ||
- ApplicationKt.module | ||
deployment: | ||
port: 8080 |