Is multiplatform Ktor really a practical technolog...
# server
j
Is multiplatform Ktor really a practical technology yet? I’ve gotten the basics working and have a basic HTTP server with HTML DSL; then this morning I tried to set up static routes to serve my static content … only to find that this functionality, and the entire io.ktor.server.http.content module, is JVM-only for some reason. (And the web page does not call this out, so I only found out when I tried to use the API in my code.) Serving static files is rock-bottom basic functionality for any web server I’ve ever used. If it’s not multiplatform in Ktor, what else isn’t? This has me doubting my decision to use Kotlin for this project (which cannot depend on the JVM.)
e
the concept of a filesystem is platform-specific (and doesn't exist on all targets)
j
Obviously. And yet every cross-platform library has a filesystem abstraction, including the JVM itself. Kotlin Multiplatform has
kotlinx.io.files
, so why doesn’t the static-file module use that?
In the meantime I’ve found a cross-platform shim; but my point remains, is this going to happen over and over as I try to use other Ktor features?
e
kotlinx.io didn't get filesystem support until last year, and ktor static content has existed since before then
yes there are many parts of ktor that have different features on different platform, unfortunately. TLS is another such feature that doesn't have a simple solution
j
Ugh, TLS! Been there. Fortunately I don’t need it for this app, which uses an embedded server with a WebView as UI.
Templating is the other roadblock I’ve found so far. Every one of the HTML template engines is in Java. Fortunately Kotlin’s HTML DSL isn’t too bad; I only worry about its performance & code size.
d
When you say "no JVM", would graal work - that opens up your options potentially?
j
Possibly. But as I understand it, using GraalVM to create native binaries from Kotlin is kind of tricky and experimental. I’m already having enough pain using Gradle, I really don’t want to complicate my build process any further!
FYI, that cross-platform shim for static files that I linked to above has a gaping security hole: it lets an attacker use
/%2e%2e/
in the path to back out of the static-files directory and access files outside it, potentially anywhere in the filesystem. I posted a comment on the gist, with a fix.
e
GraalVM takes some work when there's reflection involved, but Ktor documents https://ktor.io/docs/graalvm.html
👀 1
d
Just use libraries that don't need reflection and it's all good. 😉
💯 2
l
Why wouldn't you want to use the JVM for server side stuff though? It's significantly faster than any other compiler backend.
d
FYI - for templating, if you use something compiled like JTE then it will generate classes at build time which you can then use without reflection. (Also FYI, http4k supports both static content and JTE templates 😉 )
m
@loke Not OP but I’m guessing he needs the client apps to be a server also.