nelle-observer/backend/src/main/kotlin/observer/nelle/nelleObserverBackend/Application.kt
2024-09-17 02:11:30 -06:00

46 lines
1.4 KiB
Kotlin

@file:Suppress("ktlint:standard:no-wildcard-imports")
package observer.nelle.nelleObserverBackend
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import kotlinx.coroutines.runBlocking
import observer.nelle.nelleObserverBackend.plugins.configureRouting
val logger = KotlinLogging.logger("nelle.observer API")
fun main(args: Array<String>): Unit = EngineMain.main(args)
fun Application.module() {
install(ContentNegotiation)
install(CORS) {
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Post)
allowMethod(HttpMethod.Get)
allowHeader(HttpHeaders.AccessControlAllowOrigin)
allowHeader(HttpHeaders.ContentType)
anyHost()
}
runBlocking {
val client =
HttpClient(CIO) {
// authentication setup
install(Auth) {
bearer {
loadTokens {
BearerTokens(Config().botToken, Config().botToken)
}
}
}
}
configureRouting(client)
}
}