Error from logs after deploying ktor application to Heroku

Viewed 793

I have built a test app with ktor and it works fine on my localhost , but when i upload it to heroku and processes it , it shows that build was successful but when i open the link , it says application error .

  • This is my application class :
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@kotlin.jvm.JvmOverloads
fun Application.module(testing : Boolean = true) {
    val port = System.getenv("PORT")?.toInt() ?: 23567
    embeddedServer(Netty,port){

        install(ContentNegotiation){
            jackson {
                enable(SerializationFeature.INDENT_OUTPUT)
            }
        }
        routing {
            get("/randomgames"){

                var submodel = subModel("Active", Calendar.getInstance().time.toString())
                var game1  = userCredentials("Los Angelos","California","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png",submodel)
                var game2  = userCredentials("Texas","Arizona","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png",submodel)
                var game3  = userCredentials("New York","Virginia","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png","https://cdn.pixabay.com/photo/2017/08/05/11/16/logo-2582748_1280.png",submodel)
                var gamesList = arrayListOf<userCredentials>()
                gamesList.add(game1)
                gamesList.add(game2)
                gamesList.add(game3)

                var mainModel = MainModel(gamesList)

                call.respond(mainModel)
            }

        }
    }.start(wait = true)

}
  • This is applicationconf file
ktor {
    deployment {
        environment = development
         port = ${PORT}
    }
    application {
        modules = [ ktor.api.com.ApplicationKt.module ]
    }
}

  • This is my Procfile :
web: build/install/kotlinserver/bin/kotlinserver

*This is my gradle :

buildscript {
    repositories {
        jcenter()


    }
    
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
group 'ktor.api.com'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = "io.ktor.server.netty.EngineMain"

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

sourceSets {
    main.kotlin.srcDirs = main.java.srcDirs = ['src']
    test.kotlin.srcDirs = test.java.srcDirs = ['test']
    main.resources.srcDirs = ['resources']
    test.resources.srcDirs = ['testresources']
}

task stage {
    dependsOn installDist
    println "Running Stage"
}

repositories {
    mavenLocal()
    jcenter()
    maven { url 'https://kotlin.bintray.com/ktor' }
    maven { url 'https://kotlin.bintray.com/kotlin-js-wrappers' }
    maven { url "https://plugins.gradle.org/m2/" }
    maven {url 'https://jitpack.io'}
    maven {url 'https://github.com/psiegman/mvn-repo/raw/master/releases'}
    maven {url 'http://dl.bintray.com/kotlin/kotlinx.html'}
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "io.ktor:ktor-server-netty:$ktor_version"
    implementation "ch.qos.logback:logback-classic:$logback_version"
    implementation "io.ktor:ktor-server-core:$ktor_version"
    implementation "io.ktor:ktor-jackson:$ktor_version"
    implementation "io.ktor:ktor-gson:$ktor_version"
    implementation "io.ktor:ktor-auth:$ktor_version"
    implementation "io.ktor:ktor-html-builder:$ktor_version"
    implementation "org.jetbrains:kotlin-css-jvm:1.0.0-pre.31-kotlin-1.2.41"
    implementation "io.ktor:ktor-client-core:$ktor_version"
    implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-apache:$ktor_version"
    testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}

  • This is error from my cmd after connecting to my heroku account and fetching logs
// it show this error related to procfile 
bash: build/install/kotlinserver/bin/kotlinserver: No such file or directory

//and this is H10 error code 
2020-09-19T12:38:18.476773+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=aqueous-reaches-02639.herokuapp.com request_id=0dbb86c9-0bf1-4aac-acd6-0825c938b3ba fwd="41.200.180.139" dyno= connect= service= status=503 bytes= protocol=https
2020-09-19T12:38:19.256239+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=aqueous-reaches-02639.herokuapp.com request_id=d8bf7249-4f8a-4423-889a-81baca206ba4 fwd="41.200.180.139" dyno= connect= service= status=503 bytes= protocol=https

PS : The way i'm deploying my ktor app is by simply creating a git and commit my files , then inside heroku website , i create an app and connect to my github and deploy the app , any help would be appreciated guys thank you .

1 Answers

I fixed same issue just now

'kotlinserver' was wrong name, I did check it by running gradlew stage in console, and going to path specified in Procfile (build/install/...) the correct name is the project(module) name, I think.

also wanna mention few things

  • at first ${PORT} in application.conf file will receive system env var value, so u don't need to do things with val port = System.getenv("PORT")?.toInt() ?: 23567 in your application module function. Adding 2 lines in application.conf such as following port = 8080 port = ${?PORT} will set port to 8080 and then to SystemEnv PORT if it exists
  • for second just wanna remind, not forget to run heroku ps:scale web=1 for your app (you can also specify app here by adding (-a [app-name]) before web=1
Related