2020-04-04 18:47:24 +02:00
|
|
|
package com.kmalbz
|
|
|
|
|
2020-04-06 00:53:56 +02:00
|
|
|
import com.kmalbz.api.route.OutputServiceRDBServer
|
2020-04-04 18:47:24 +02:00
|
|
|
import io.ktor.application.*
|
|
|
|
import io.ktor.response.*
|
|
|
|
import io.ktor.routing.*
|
|
|
|
import io.ktor.http.*
|
|
|
|
import io.ktor.features.*
|
2020-04-04 23:21:17 +02:00
|
|
|
import org.apache.http.HttpException
|
2020-04-05 11:14:02 +02:00
|
|
|
import com.kmalbz.database.DatabaseFactory
|
2020-04-06 00:53:56 +02:00
|
|
|
import com.kmalbz.database.dao.ResultObjects
|
2021-08-18 16:44:29 +02:00
|
|
|
import io.ktor.serialization.*
|
2020-04-05 11:14:02 +02:00
|
|
|
import io.ktor.util.KtorExperimentalAPI
|
2020-04-06 00:53:56 +02:00
|
|
|
import org.jetbrains.exposed.sql.SchemaUtils
|
2020-04-06 01:43:43 +02:00
|
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
2020-05-20 17:06:15 +02:00
|
|
|
import org.koin.ktor.ext.Koin
|
2020-04-04 18:47:24 +02:00
|
|
|
|
|
|
|
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
|
|
|
|
2020-04-05 11:14:02 +02:00
|
|
|
@KtorExperimentalAPI
|
2020-04-04 18:47:24 +02:00
|
|
|
@Suppress("unused") // Referenced in application.conf
|
2020-05-20 14:59:08 +02:00
|
|
|
fun Application.module() {
|
2020-04-04 18:47:24 +02:00
|
|
|
install(ContentNegotiation) {
|
2021-08-18 16:44:29 +02:00
|
|
|
json()
|
2020-04-04 18:47:24 +02:00
|
|
|
}
|
2020-05-20 17:12:29 +02:00
|
|
|
|
2020-05-20 17:06:15 +02:00
|
|
|
install(Koin) {
|
|
|
|
printLogger()
|
|
|
|
modules(com.kmalbz.di.injectionModule)
|
|
|
|
}
|
2020-04-04 18:47:24 +02:00
|
|
|
|
2020-04-05 11:14:02 +02:00
|
|
|
DatabaseFactory.init()
|
2020-04-06 01:43:43 +02:00
|
|
|
transaction{
|
|
|
|
SchemaUtils.create(ResultObjects)
|
|
|
|
}
|
|
|
|
|
2020-04-04 18:47:24 +02:00
|
|
|
routing {
|
|
|
|
install(StatusPages) {
|
2020-05-20 14:59:08 +02:00
|
|
|
exception<HttpException> {
|
2020-04-04 23:21:17 +02:00
|
|
|
call.respond(HttpStatusCode.BadRequest)
|
2020-04-04 18:47:24 +02:00
|
|
|
}
|
2020-04-06 01:43:43 +02:00
|
|
|
|
2020-05-20 14:59:08 +02:00
|
|
|
exception<IllegalStateException> {
|
2020-04-06 01:43:43 +02:00
|
|
|
call.respond(HttpStatusCode.NotAcceptable)
|
|
|
|
}
|
2020-04-04 18:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OutputServiceRDBServer().apply {
|
|
|
|
registerOutput()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|