https://kotlinlang.org logo
Title
d

Dominick

04/28/2021, 5:44 AM
Whenever I run Ktor with Exposed, only the one that comes first actually works. For example, if I put the database stuff above the install if-statement, Hikari works fine and I get a bunch of console spam of hikari logs, however ktor doesn't connect. If I put Exposed at the bottom, ktor works but exposed doesn't. routing above transaction & datasource 2021-04-28 01:42:59.490 [main] INFO Application - Responding at http://0.0.0.0:2828 2021-04-28 01:42:59.490 [main] INFO Application - Responding at https://0.0.0.0:1818 routing below database stuff: 2021-04-28 01:34:18.495 [main] INFO Application - No ktor.deployment.watch patterns specified, automatic reload is not active 2021-04-28 01:34:18.942 [main] DEBUG com.zaxxer.hikari.HikariConfig - Driver class com.mysql.cj.jdbc.Driver found in Thread context class loader sun.misc.Launcher$AppClassLoader@1b6d3586 2021-04-28 01:34:19.026 [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration: ....
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
    // <https://ktor.io/servers/features/https-redirect.html#testing>
    if (!testing) {
        install(HttpsRedirect) {
            // The port to redirect to. By default 443, the default HTTPS port.
            sslPort = 1818
            // 301 Moved Permanently, or 302 Found redirect.
            permanentRedirect = true
        }
    }
    install(ContentNegotiation) {
        gson {}
    }

    routing {
        userRoutes()
        /*
        fileRoutes()
        miscRoutes()
        deliveryRoutes()
        */

        static("/") {
            files("public")
            default("public/index.html")
        }
    }

    val dataSource = HikariDataSource().apply {
        maximumPoolSize = 20
        driverClassName = "com.mysql.cj.jdbc.Driver"
        jdbcUrl = "[removed]"
        addDataSourceProperty("user", "mediauser")
        addDataSourceProperty("password", "[removed]")
        isAutoCommit = false
    }

    Database.Companion.connect(dataSource)

    transaction {
        addLogger(StdOutSqlLogger)
        SchemaUtils.create(MediaPropertiesTable, MediaContentTable, UserAPIKeysTable, UserTable)
    }

    Thread(ConsoleRunnable).run()
}
:thread-please: 2
l

Lynette Midy

06/17/2021, 10:34 PM
Have you considered breaking this up into separate files vs all in one?