Janez Kolar
10/06/2020, 5:51 PMfun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
val demo: Demo = Demo()
val compute = newFixedThreadPoolContext(10, "compute")
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
demo.generateflyingDemo()
GlobalScope.launch(Dispatchers.Default) {
while(isActive)
{
demo.demoMoving()
delay(1000)
}
}
install(Compression) {
gzip {
priority = 1.0
minimumSize(256)
}
deflate {
priority = 10.0
minimumSize(1024) // condition
}
}
install(CORS) {
method(HttpMethod.Options)
method(HttpMethod.Put)
method(HttpMethod.Delete)
method(HttpMethod.Patch)
method(HttpMethod.Get)
header(HttpHeaders.Authorization)
header(HttpHeaders.Origin)
header(HttpHeaders.XRequestId)
allowCredentials = true
anyHost() // @TODO: Don't do this in production if possible. Try to limit it.
}
install(WebSockets) {
pingPeriod = Duration.ofSeconds(15)
timeout = Duration.ofSeconds(15)
maxFrameSize = Long.MAX_VALUE
masking = false
}
install(Authentication) {
basic("myBasicAuth") {
realm = "Ktor Server"
validate { if (it.name == "test" && it.password == "password") UserIdPrincipal(it.name) else null }
}
}
install(ContentNegotiation) {
gson {
}
}
routing {
get("rc/activePeople") {
call.respondHandlingActivePeople()
}
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
}
}
private suspend fun ApplicationCall.respondHandlingActivePeople() {
withContext(compute) {
respond(demo.activePeople(age = 15))
}
}
jorge.rego
10/08/2020, 8:06 AM