I started a new project in IntelliJ - "multiplatfo...
# ktor
r
I started a new project in IntelliJ - "multiplatform full stack web application". By default, it has a ktor route
static("/static") { resources() }
, which serves the compiled JS. Problem is: it serves all resources! Insecure, no? How do I change the gradle file to copy the compiled JS into a subdir? (More in thread)
In the ktor/kotlin code, this is easy. I can say:
resources("web")
and it will only serve resources starting with "web/". But Gradle is opaque to me, and I don't know how to change it to put the JS output there. Maybe there is another way to filter what
resources(...)
will serve up. I don't want to expose things like
application.conf
.
a
To put JS file into
web
package inside the JAR you can replace the line
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName))
in the
build.gradle.kts
file with the following lines:
Copy code
into("web") {
    from(File(webpackTask.destinationDirectory, webpackTask.outputFileName))
}
r
In my new project, that line is not present in
build.gradle.kts
. After the
kotlin { ... }
block, there are only two "tasks":
Copy code
tasks.named<Copy>("jvmProcessResources") {
    val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
    from(jsBrowserDistribution)
}

tasks.named<JavaExec>("run") {
    dependsOn(tasks.named<Jar>("jvmJar"))
    classpath(tasks.named<Jar>("jvmJar"))
}
a
Then try to replace
from(jsBrowserDistribution)
with the following lines:
Copy code
into("web") {
    from(jsBrowserDistribution)
}
🙏 1