From 31fdcf74a51b4b4d8ec4802a7080dd8e30cfaac8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 Nov 2021 13:24:45 +0600 Subject: [PATCH] ktor server createKtorServer extensions --- CHANGELOG.md | 4 +++ .../micro_utils/ktor/server/StartServer.kt | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 577d89690b2..54b0a346e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.8.4 +* `Ktor`: + * `Server`: + * Several new `createKtorServer` + ## 0.8.3 * `Common`: diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt index 1a50ca884b6..59ff509aecf 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt @@ -1,5 +1,6 @@ package dev.inmo.micro_utils.ktor.server +import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator import io.ktor.application.Application import io.ktor.server.cio.CIO import io.ktor.server.engine.* @@ -31,3 +32,27 @@ fun createKtorServer( port: Int = Random.nextInt(1024, 65535), block: Application.() -> Unit ): ApplicationEngine = createKtorServer(CIO, host, port, block) + +fun createKtorServer( + engine: ApplicationEngineFactory, + host: String = "localhost", + port: Int = Random.nextInt(1024, 65535), + configurators: List +): TEngine = createKtorServer( + engine, + host, + port +) { + configurators.forEach { it.apply { configure() } } +} + +/** + * Create server with [CIO] server engine without starting of it + * + * @see ApplicationEngine.start + */ +fun createKtorServer( + host: String = "localhost", + port: Int = Random.nextInt(1024, 65535), + configurators: List +): ApplicationEngine = createKtorServer(CIO, host, port, configurators)