package de.walamana

import de.walamana.plugins.*
import de.walamana.views.*
import io.github.cdimascio.dotenv.dotenv
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.routing.*

//fun main() {
//    embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
//        .start(wait = true)
//}

fun main(args: Array<String>): Unit {
    dotenv {
        ignoreIfMissing = true
        ignoreIfMalformed = true
        systemProperties = true
    }
    EngineMain.main(args)
}

fun Application.module() {
    configureSecurity()
    configureHTTP()
    configureSerialization()
    configureDatabases()

    routing {
        singlePageApplication {
            vue(System.getenv("FRONTEND_PATH"))
        }
        route("/api") {
            configureMinistrantenRoutes()
            configureGottesdiensteRoutes()
            configureMarksView()
            configurePlanRoutes()
            configureAuthenticationRoutes()
        }
    }
}
