Compare commits

..

No commits in common. "ba16bad0293b087ab77e540109c946bebaabf6dd" and "49c139e235b96cddc767d620a22c4934af53d879" have entirely different histories.

3 changed files with 13 additions and 39 deletions

View File

@ -1,11 +1,5 @@
# Changelog # Changelog
## 0.9.22
* `Ktor`:
* `Server`:
* Now `createKtorServer` fun is fully customizable
## 0.9.21 ## 0.9.21
* `Repos`: * `Repos`:

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.9.22 version=0.9.21
android_code_version=112 android_code_version=111

View File

@ -3,7 +3,6 @@ package dev.inmo.micro_utils.ktor.server
import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator
import io.ktor.application.Application import io.ktor.application.Application
import io.ktor.server.cio.CIO import io.ktor.server.cio.CIO
import io.ktor.server.cio.CIOApplicationEngine
import io.ktor.server.engine.* import io.ktor.server.engine.*
import kotlin.random.Random import kotlin.random.Random
@ -11,21 +10,17 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
engine: ApplicationEngineFactory<TEngine, TConfiguration>, engine: ApplicationEngineFactory<TEngine, TConfiguration>,
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
block: Application.() -> Unit block: Application.() -> Unit
): TEngine = embeddedServer( ): TEngine {
engine, val env = applicationEngineEnvironment {
applicationEngineEnvironment {
module(block) module(block)
connector { connector {
this.host = host this@connector.host = host
this.port = port this@connector.port = port
}
}
return embeddedServer(engine, env)
} }
additionalEngineEnvironmentConfigurator()
},
additionalConfigurationConfigurator
)
/** /**
* Create server with [CIO] server engine without starting of it * Create server with [CIO] server engine without starting of it
@ -35,31 +30,18 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
fun createKtorServer( fun createKtorServer(
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
block: Application.() -> Unit block: Application.() -> Unit
): CIOApplicationEngine = createKtorServer( ): ApplicationEngine = createKtorServer(CIO, host, port, block)
CIO,
host,
port,
additionalEngineEnvironmentConfigurator,
additionalConfigurationConfigurator,
block
)
fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> createKtorServer( fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration> createKtorServer(
engine: ApplicationEngineFactory<TEngine, TConfiguration>, engine: ApplicationEngineFactory<TEngine, TConfiguration>,
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
configurators: List<KtorApplicationConfigurator> configurators: List<KtorApplicationConfigurator>
): TEngine = createKtorServer( ): TEngine = createKtorServer(
engine, engine,
host, host,
port, port
additionalEngineEnvironmentConfigurator,
additionalConfigurationConfigurator
) { ) {
configurators.forEach { it.apply { configure() } } configurators.forEach { it.apply { configure() } }
} }
@ -72,7 +54,5 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
fun createKtorServer( fun createKtorServer(
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
configurators: List<KtorApplicationConfigurator>, configurators: List<KtorApplicationConfigurator>
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {}, ): ApplicationEngine = createKtorServer(CIO, host, port, configurators)
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)