https://kotlinlang.org logo
#ktor
Title
# ktor
r

robnik

02/25/2022, 10:18 PM
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

Aleksei Tirman [JB]

02/27/2022, 9:22 AM
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

robnik

02/27/2022, 3:21 PM
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

Aleksei Tirman [JB]

02/28/2022, 7:05 AM
Then try to replace
from(jsBrowserDistribution)
with the following lines:
Copy code
into("web") {
    from(jsBrowserDistribution)
}
🙏 1
5 Views