I do something similar with Kotlin 1.3.71 in a multiplatform project with a JS frontend and a JVM backend with Ktor. During development I just run the backend on its own using a JavaExec task:
register<JavaExec>("jvmServerRun") {
classpath = output.allOutputs + configurations["jvmRuntimeClasspath"]
main = "io.ktor.server.netty.EngineMain"
}
and serve the frontend using Webpack DevServer with a proxy:
browser {
runTask {
devServer = devServer?.copy(
port = 8088,
proxy = mapOf("/api" to "http://localhost:8080")
)
}
}
When I want to deploy everything I want to serve the frontend from the Ktor server. To achieve this I copy the generated JS bundle and resources (index.html + source map) to a sub folder of the processed resources of the JVM distribution before I build the fat jar for the server:
register<Copy>("copyJsBundleToKtor") {
from("$distsDir")
into("$buildDir/processedResources/jvm/main/web")
}
register("stage") {
dependsOn("jsBrowserProductionWebpack", "copyJsBundleToKtor", "fatJar")
}
named("copyJsBundleToKtor") {
mustRunAfter("jsBrowserProductionWebpack")
}
named("fatJar") {
mustRunAfter("copyJsBundleToKtor")
}
And then Ktor serves the JS parts using a static route:
routing {
static("/") {
resources("web")
defaultResource("web/index.html")
}