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

Tobias

11/13/2023, 9:03 AM
Hi team, I have some troubles getting Ktor server on a Kotlin Native target the routing up and running for serving static files.
Copy code
routing {
    get("/") {
        call.respondText("Hi") // works

        val bytes = resource("index.html").readBytes() // resources method not found
        call.respondText(contentType = ContentType.Text.Html, text = bytes.decodeToString())
    }

    // staticResources not found
    staticResources("/", "static") {
        default("index.html")
        preCompressed(CompressedFileType.GZIP)
   }
}
Is this a limitation of Kotlin native or did I miss something else?
1
a

Aleksei Tirman [JB]

11/14/2023, 8:21 AM
Unfortunately, methods for serving static content are available only on the JVM target.
t

Tobias

11/14/2023, 8:25 AM
Thanks for the clarification @Aleksei Tirman [JB], just for learning purpose, do you know y?
a

Aleksei Tirman [JB]

11/14/2023, 8:32 AM
Because a JVM specific API is used there which requires an implementation on the *nix targets.
t

Tobias

11/14/2023, 8:33 AM
thx 🙂