How do I setup static routing with the Native vers...
# ktor
n
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")
        file("index.html")
        default("index.html")
        static("assets") {
            files("css")
            files("js")
        }
    }
For some reason all the missing imports cannot be completed. The main exception to this is
File
.
@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.
a
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.
n
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 🎉 : https://gitlab.com/data-conduit/conduit-server/-/tree/web-client
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.
l
Nothing has changed in the last year right? I made an example multiplatform project using the gist from @Aleksei Tirman [JB] here: https://github.com/luca992/multiplatform-static-content-ktor-server
n
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 😁 .
140 Views