From 53d35d74b3327ce7807b8841033df923f74d7d2c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Apr 2022 11:14:50 +0600 Subject: [PATCH 1/2] start 0.9.22 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47f358bfd57..717f4df5a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.9.22 + ## 0.9.21 * `Repos`: diff --git a/gradle.properties b/gradle.properties index 0bd6476919b..1c89047d5db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.9.21 -android_code_version=111 +version=0.9.22 +android_code_version=112 From ca8ae4cd72ee048c8b2e13e2c69ffbcc96cc403e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Apr 2022 11:16:04 +0600 Subject: [PATCH 2/2] improve ktor server part --- CHANGELOG.md | 4 ++ .../micro_utils/ktor/server/StartServer.kt | 42 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 717f4df5a99..f398f836d57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.9.22 +* `Ktor`: + * `Server`: + * Now `createKtorServer` fun is fully customizable + ## 0.9.21 * `Repos`: 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 59ff509aecf..51948300ba2 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 @@ -3,6 +3,7 @@ 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.cio.CIOApplicationEngine import io.ktor.server.engine.* import kotlin.random.Random @@ -10,17 +11,21 @@ fun , host: String = "localhost", port: Int = Random.nextInt(1024, 65535), + additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {}, + additionalConfigurationConfigurator: TConfiguration.() -> Unit = {}, block: Application.() -> Unit -): TEngine { - val env = applicationEngineEnvironment { +): TEngine = embeddedServer( + engine, + applicationEngineEnvironment { module(block) connector { - this@connector.host = host - this@connector.port = port + this.host = host + this.port = port } - } - return embeddedServer(engine, env) -} + additionalEngineEnvironmentConfigurator() + }, + additionalConfigurationConfigurator +) /** * Create server with [CIO] server engine without starting of it @@ -30,18 +35,31 @@ fun Unit = {}, + additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {}, block: Application.() -> Unit -): ApplicationEngine = createKtorServer(CIO, host, port, block) +): CIOApplicationEngine = createKtorServer( + CIO, + host, + port, + additionalEngineEnvironmentConfigurator, + additionalConfigurationConfigurator, + block +) fun createKtorServer( engine: ApplicationEngineFactory, host: String = "localhost", port: Int = Random.nextInt(1024, 65535), + additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {}, + additionalConfigurationConfigurator: TConfiguration.() -> Unit = {}, configurators: List ): TEngine = createKtorServer( engine, host, - port + port, + additionalEngineEnvironmentConfigurator, + additionalConfigurationConfigurator ) { configurators.forEach { it.apply { configure() } } } @@ -54,5 +72,7 @@ fun -): ApplicationEngine = createKtorServer(CIO, host, port, configurators) + configurators: List, + additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {}, + additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {}, +): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)