gpt4 book ai didi

kotlin - 将 ktor 应用程序部署到 Heroku 后日志出错

转载 作者:行者123 更新时间:2023-12-05 07:00:59 31 4
gpt4 key购买 nike

我用 ktor 构建了一个测试应用程序,它在我的本地主机上运行良好,但是当我将它上传到 heroku 并处理它时,它显示构建成功但是当我打开链接时,它显示应用程序错误。

  • 这是我的应用程序类:
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)

}
  • 这是应用配置文件
ktor {
deployment {
environment = development
port = ${PORT}
}
application {
modules = [ ktor.api.com.ApplicationKt.module ]
}
}

  • 这是我的过程文件:
web: build/install/kotlinserver/bin/kotlinserver

*这是我的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"
}

  • 这是连接到我的 heroku 帐户并获取日志后我的 cmd 出现的错误
// 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:我部署我的 ktor 应用程序的方式是简单地创建一个 git 并提交我的文件,然后在 heroku 网站内,我创建一个应用程序并连接到我的 github 并部署该应用程序,任何帮助将不胜感激谢谢。

最佳答案

我刚刚解决了同样的问题

'kotlinserver' 是错误的名称,我通过在控制台中运行 gradlew stage 并转到 Procfile 中指定的路径(build/install/...)来检查它我认为正确的名称是项目(模块)名称。

还想提一些事情

  • 首先${PORT}application.conf文件将接收系统环境变量值,所以你不需要用 val port = System.getenv("PORT")?.toInt() ?: 23567 做任何事情在您的应用程序模块功能中。在 application.conf 中添加 2 行例如以下 port = 8080 port = ${?PORT}将端口设置为 8080,然后设置为 SystemEnv PORT(如果存在)
  • 第二次只是想提醒一下,别忘了跑heroku ps:scale web=1对于您的应用程序(您也可以通过在 web=1
  • 之前添加 (-a [app-name]) 在此处指定应用程序

关于kotlin - 将 ktor 应用程序部署到 Heroku 后日志出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63968947/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com