can some one point me to a resource or let me know...
# compose-web
d
can some one point me to a resource or let me know how to use ktor as a backend to serve a compose-web client?
👍 1
Not compose-web client, but it doesn't matter sine ktor is just serving js
But if you really need compose setup, I'm currently reworking that app with compose-web on another branch https://github.com/mpetuska/kamp/tree/feature%2Fcompose/app
c
Essentially the idea would be to copy the JS file generated by Compose into the Ktor server's resource directory, and then tell Ktor to serve it. Here are the exact changes I did to enable that: https://gitlab.com/arcachon-ville/formulaide/-/merge_requests/18/diffs My case is a Kotlin React app, not Kotlin Compose, but it's exactly the same.
d
thanks for the helpful examples. do you guys have any examples for routing? like if i click a button on the home page, how do I want to make it take me to the about page/component instead?
b
Use react-router-dom
d
or if i want to call an endpoint with query parameters or something? right now i'm running into cors errors trying to use ktor to get a response from a website like ktor.io in the example
oh will that work well with compose?
i've never used it
b
Oh wait, it's compose. Then just use hash routing and render your tree depending on parsed hash path
Bit manual, though
d
https://github.com/hfhbd/routing-compose this lib looks like it could work pretty well
jetpack compose 1
h
Often it does 😄 BTW the idea of server side rending, like the old days with PHP, is not (yet, maybe never) possible with Compose: https://ktor.io/docs/html-dsl.html#html_response You do have to create a new Gradle module, implement your JS application, create the executable js file and serve it with Ktor. (of course you could rendering your
index.html
file with Ktor...) The packing could be done by Gradle tasks, see the official Ktor server templates created by the Kotlin plugin (new project, Kotlin, server template).