Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions codeSnippets/snippets/embedded-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("io.ktor:ktor-server-jetty-jakarta:$ktor_version")
implementation("io.ktor:ktor-server-cio:$ktor_version")
implementation("io.ktor:ktor-server-tomcat-jakarta:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")

testImplementation("junit:junit:$junit_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,49 @@ fun runServerWithCommandLineConfig(args: Array<String>) {
}
}
}.start(wait = true)
}
}

fun runConfiguredCommonProperties() {
embeddedServer(Netty, configure = {
connector {
host = "0.0.0.0"
port = 8080
}
connectionGroupSize = 2
workerGroupSize = 5
callGroupSize = 10
shutdownGracePeriod = 2000
shutdownTimeout = 3000
}) {
module()
}.start(wait = true)
}

fun io.ktor.server.application.Application.module() {
routing {
get("/") {
call.respondText("Hello, world!")
}
}
}

fun runConfiguredNettyProperties() {
embeddedServer(Netty, configure = {
runningLimit = 16
shareWorkGroup = false
configureBootstrap = {
// ...
}
channelPipelineConfig = {
//
}
responseWriteTimeoutSeconds = 10
requestReadTimeoutSeconds = 0 // infinite
tcpKeepAlive = false
maxInitialLineLength = 4096
maxHeaderSize = 8192
maxChunkSize = 8192
}) {
module()
}.start(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example

import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer

fun runConfiguredCIOProperties() {
embeddedServer(CIO, configure = {
connectionIdleTimeoutSeconds = 45
reuseAddress = false
}) {
module()
}.start(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example

import io.ktor.server.engine.embeddedServer
import io.ktor.server.jetty.jakarta.Jetty
import org.eclipse.jetty.server.handler.ErrorHandler
import kotlin.time.Duration.Companion.seconds

fun runConfiguredJettyProperties() {
embeddedServer(Jetty, configure = {
configureServer = {
errorHandler = MyErrorHandler()
}
idleTimeout = 30.seconds
}) {
module()
}.start(true)
}

class MyErrorHandler : ErrorHandler()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example

import io.ktor.server.engine.embeddedServer
import io.ktor.server.tomcat.jakarta.Tomcat

fun runConfiguredTomcatProperties() {
embeddedServer(Tomcat, configure = {
configureTomcat = {
with(connector) {
enableLookups = false
setProperty("maxThreads", "150")
}
}
}) {
module()
}.start(true)
}
7 changes: 3 additions & 4 deletions ktor.tree
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@
<toc-element topic="server-engines.md"
toc-title="Engines"
accepts-web-file-names="custom-engines.html,engines.html"/>
<toc-element topic="server-configuration-code.topic"
accepts-web-file-names="configuration-code.html"/>
<toc-element topic="server-configuration-file.topic"
accepts-web-file-names="configuration.html,configurations.html,environments.html,configuration-file.html"/>
<toc-element topic="server-configuration.md"
toc-title="Server Configuration"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing that the TOC title is "Server Configuration" but the topic one "Application Configuration". If I understand correctly, they are separate concepts, so we should either call this "Configuration" or "Server and application configuration". Wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably oversight. I thought Server and application configuration was too long for the menu 😅
I think Server configuration, Application configuration, or Server and Application Configuration all work.

Server configuration implies both "ktor server" and "my custom server logic", similarly for Application it refers to my own Application and the Ktor Application class.

I personally have no strong opinion. It could also be moved "Ktor Configuration" to "Engines" but then we'd have to change the name and I think that might be move confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then, I think it makes sense to keep the Ktor configurations here as opposed to the Engines topic.
Maybe @meilalina can help with the title :)

accepts-web-file-names="configuration.html,configurations.html,environments.html,configuration-file.html, configuration-code.html" />
<toc-element topic="server-modules.md"
accepts-web-file-names="modules.html"/>
<toc-element topic="server-plugins.md"
Expand Down
4 changes: 2 additions & 2 deletions topics/lib.topic
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@
<control>Configuration</control>
:
Choose whether
to specify server parameters <a href="server-configuration-file.topic">in a YAML or HOCON file</a>, or
<a href="server-configuration-code.topic">in code</a>.
to specify server parameters <a href="server-configuration.md">in a YAML or HOCON file</a>, or
<a href="server-configuration.md">in code</a>.
</p>
</snippet>

Expand Down
2 changes: 1 addition & 1 deletion topics/migrating-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fun main(args: Array<String>) {
</compare>

For more information on command-line configuration with `embeddedServer`, see the
[Configuration in code](server-configuration-code.topic#command-line) topic.
[Configuration in code](server-engines.md#configure-engine) topic.

#### Introduction of `ServerConfigBuilder` {id="ServerConfigBuilder"}

Expand Down
Loading