【发布时间】:2021-01-06 04:07:18
【问题描述】:
我已经用 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 ]
}
}
- 这是我的 Procfile:
web: build/install/kotlinserver/bin/kotlinserver
*这是我的毕业典礼:
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 并部署该应用程序,任何帮助将不胜感激谢谢。
【问题讨论】:
-
如果你想在 heroku 上部署 ktor 应用 .. 请阅读这篇关于 ktor 应用部署的中型博客nameisjayant.medium.com/…