mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-18 14:23:50 +00:00
commit
ba16bad029
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.9.22
|
||||||
|
|
||||||
|
* `Ktor`:
|
||||||
|
* `Server`:
|
||||||
|
* Now `createKtorServer` fun is fully customizable
|
||||||
|
|
||||||
## 0.9.21
|
## 0.9.21
|
||||||
|
|
||||||
* `Repos`:
|
* `Repos`:
|
||||||
|
@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.9.21
|
version=0.9.22
|
||||||
android_code_version=111
|
android_code_version=112
|
||||||
|
@ -3,6 +3,7 @@ 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
|
||||||
|
|
||||||
@ -10,17 +11,21 @@ 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 {
|
): TEngine = embeddedServer(
|
||||||
val env = applicationEngineEnvironment {
|
engine,
|
||||||
|
applicationEngineEnvironment {
|
||||||
module(block)
|
module(block)
|
||||||
connector {
|
connector {
|
||||||
this@connector.host = host
|
this.host = host
|
||||||
this@connector.port = port
|
this.port = port
|
||||||
}
|
}
|
||||||
}
|
additionalEngineEnvironmentConfigurator()
|
||||||
return embeddedServer(engine, env)
|
},
|
||||||
}
|
additionalConfigurationConfigurator
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create server with [CIO] server engine without starting of it
|
* Create server with [CIO] server engine without starting of it
|
||||||
@ -30,18 +35,31 @@ 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
|
||||||
): ApplicationEngine = createKtorServer(CIO, host, port, block)
|
): CIOApplicationEngine = createKtorServer(
|
||||||
|
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() } }
|
||||||
}
|
}
|
||||||
@ -54,5 +72,7 @@ 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>,
|
||||||
): ApplicationEngine = createKtorServer(CIO, host, port, configurators)
|
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||||
|
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
|
||||||
|
): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)
|
||||||
|
Loading…
Reference in New Issue
Block a user