How do I setup static routing with the Native vers...
# ktor
How do I setup static routing with the Native version of Ktor Server? I tried doing the following to setup static routing:
Copy code
// ...
    static("/") {
        staticRootFolder = File("files")
        static("assets") {
For some reason all the missing imports cannot be completed. The main exception to this is
@Aleksei Tirman [JB] - Is there an alternative way to setup static routing with the Native version of Ktor Server?
Is static routing setup by default with Ktor Server, and if so what are the defaults?
I am trying to get the server to serve up files generated by the KVision based frontend.
Unfortunately, routing methods for serving static files are implemented for JVM only. Here is the gist with the solution for your setup where the okio library is used to work with files on the native platform.
On doing a search in the Ktor Issue Tracker there doesn't seem to be an issue, which covers missing functionality to serve static resources with the Native version of Ktor Server.
After a marathon effort I have managed to get some static resources served by the backend 🎉 :
General I/O has been covered using POSIX instead of Okio for portability reasons. In the near future I would like to add support for the Linux ARM targets. Okio is mainly focused on the mobile side, and has very limited Linux support (only the linuxX64 target is supported). At least with POSIX, porting the general I/O logic would require minor changes on a very micro scale (very easy to cover). Kotlin Native does have the Cinterop Commonizer which covers this use case, however it isn't production ready.
Nothing has changed in the last year right? I made an example multiplatform project using the gist from @Aleksei Tirman [JB] here:
Did something similar a while back for one of the Kotlin Native projects (might have been the Serverless one involving Kotlin Native and Ktor Server). So many Kotlin Native projects have been done over the years that I have built up a reasonable portfolio 😁 .