Martin Gaens
02/03/2023, 10:59 PMrun
Gradle task and with it at the same time the build
task with the -t
parameter for continuous build and it works, however, it is EXTREMELY slow. The recompilation of the app can take over 2 minutes (with almost no source files) so it is completely unusable for a hot reload type of situation which I'm in. What do people do while developing these web apps?
Also, the jsBrowserDevelopmentRun
task doesn't work because when I run it, the backend isn't running so I can't access the JS files that have been compiled since there is no server to server them to my browser...Robert Jaros
02/04/2023, 9:21 AMMartin Gaens
02/04/2023, 10:47 AMRobert Jaros
02/04/2023, 10:57 AMjsBrowserDevelopmentRun
).Martin Gaens
02/04/2023, 11:01 AMapplication
Gradle plugin, so the backend can be run by the run
task. However, the run
task in this case compiles everything (even the frontend) and all my changes are updated. When I run the frontend separately, by running jsBrowserDevelopmentRun -t
, it starts a new development server on the next available port (8081 in my case because 8080 is occupied by the server that's running through the run
task) and it says "Cannot get /". When I access the website localhost:8080
, I can see the webpage, however, it doesn't get any updates even though after making some changes, I can clearly see Gradle recompiling something in the jsBrowserDevelopmentRun
task, the changes won't end up in my webpage. It's as if the backend isn't notified of the changes made to the frontend.Robert Jaros
02/04/2023, 11:04 AMjvmRun
?) which runs your backend without compiling everything.Robert Jaros
02/04/2023, 11:07 AMindex.html
file served by the webpack. And to make your frontend app access your backend (API), user webpack proxy configuration.Robert Jaros
02/04/2023, 11:08 AMMartin Gaens
02/04/2023, 11:08 AMjvmRun
. The tasks with "jvm" in the name are:
jvmJar
, jvmMainClasses
, jvmSourcesJar
, jvmTestClasses
, compileKotlinJvm
, jvmProcessResources
, jvmTestProcessResources
, jvmTest
.Robert Jaros
02/04/2023, 11:09 AMRobert Jaros
02/04/2023, 11:09 AMMartin Gaens
02/04/2023, 11:10 AMindex.html
file, the frontend is written in React. It's the project IntelliJ IDEA generates when you select "Kotlin Multiplatform -> Fullstack Web application" and leave everything default.Robert Jaros
02/04/2023, 11:12 AMMartin Gaens
02/04/2023, 11:14 AMRobert Jaros
02/04/2023, 11:18 AMMartin Gaens
02/04/2023, 11:20 AMjsMain
kind of was the culprit. However, the thing is, there was no need of an index.html
in the first place, because the index.html
was declared in Kotlin code inside the server's backend like this:
fun HTML.index() {
head {
title("Hello from Ktor!")
}
body {
div {
+"Hello from Ktor"
}
div {
id = "root"
}
script(src = "/static/vut-subject-market-kotlin.js") {}
}
}
fun main() {
embeddedServer(Netty, port = 8080, host = "127.0.0.1", module = Application::application).start(wait = true)
}
fun Application.application() {
routing {
get("/") {
call.respondHtml(HttpStatusCode.OK, HTML::index)
}
static("/static") {
resources()
}
}
}
And in the jsBrowserDevelopmentRun
task, the index.html
file is used, and not this code in the backend.Robert Jaros
02/04/2023, 11:22 AMRobert Jaros
02/04/2023, 11:22 AMRobert Jaros
02/04/2023, 11:23 AMMartin Gaens
02/04/2023, 11:28 AMbuild -t
task, which is in my large multiplatform codebase VERY slow. What are my options for developing the backend and hot reloading with Ktor then?Robert Jaros
02/04/2023, 11:29 AM-t compileKotlinJvm
task (another console)Robert Jaros
02/04/2023, 11:29 AMRobert Jaros
02/04/2023, 11:31 AMRobert Jaros
02/04/2023, 11:31 AMMartin Gaens
02/04/2023, 11:33 AMlocalhost:8080
and frontend runs at localhost:8081
and tries to find the index.html
file in the resources and is unable to do so.Robert Jaros
02/04/2023, 11:36 AMindex.html
file?Martin Gaens
02/04/2023, 11:36 AMfun HTML.index() {
head {
title("Hello from Ktor!")
}
body {
div {
+"Hello from Ktor!"
}
div {
id = "root"
}
script(src = "/static/vut-subject-market-kotlin.js") {}
}
}
Robert Jaros
02/04/2023, 11:37 AMRobert Jaros
02/04/2023, 11:39 AMRobert Jaros
02/04/2023, 11:40 AM`proxy = mutableMapOf("/*", to "<http://localhost:8080>")`
Robert Jaros
02/04/2023, 11:40 AMRobert Jaros
02/04/2023, 11:41 AM/static/...js
fileRobert Jaros
02/04/2023, 11:41 AMRobert Jaros
02/04/2023, 11:43 AMindex.html
fileRobert Jaros
02/04/2023, 11:43 AMRobert Jaros
02/04/2023, 11:44 AMMartin Gaens
02/04/2023, 11:44 AMRobert Jaros
02/04/2023, 11:45 AMRobert Jaros
02/04/2023, 11:45 AMRobert Jaros
02/04/2023, 11:47 AMMartin Gaens
02/04/2023, 12:00 PMMartin Gaens
02/04/2023, 12:00 PMMartin Gaens
02/04/2023, 12:13 PMRobert Jaros
02/04/2023, 12:14 PMRobert Jaros
02/04/2023, 12:15 PMRobert Jaros
02/04/2023, 12:15 PMRobert Jaros
02/04/2023, 12:16 PMMartin Gaens
02/04/2023, 12:17 PMRobert Jaros
02/04/2023, 12:18 PMMartin Gaens
02/04/2023, 12:18 PMjsDevelopmentRun -t
and run
are running, yet I can't access the backendMartin Gaens
02/04/2023, 12:18 PMRobert Jaros
02/04/2023, 12:19 PMproxy = mutableMapOf(...)
option in build.gradle.ktsRobert Jaros
02/04/2023, 12:19 PMRobert Jaros
02/04/2023, 12:20 PMproxy = mutableMapOf("/test" to "<http://localhost:8080>")
or use some wildcardsRobert Jaros
02/04/2023, 12:21 PMRobert Jaros
02/04/2023, 12:21 PMMartin Gaens
02/04/2023, 12:21 PMRobert Jaros
02/04/2023, 12:22 PMRobert Jaros
02/04/2023, 12:22 PMfrontend
and backend
instead of js
and jvm
Robert Jaros
02/04/2023, 12:23 PMMartin Gaens
02/04/2023, 12:28 PM