BIG Question: What do yall do for front end framew...
# ktor
g
BIG Question: What do yall do for front end frameworks with Ktor? I heard KotlinJS isn't really being developed or might be retired, I never really got it working with ktor. I don't get why ktor has CSS and HTML DSL inherent but not js. So what do people do for front end, just create JS files in the resources folder? For libraries that makes sense I guess but not custom frontend code, and I wouldn't mind moving away from JS. I mean if I write in JS why would someone write in kotlin HTML/CSS, module parts would end up isolated most likely. Trying to understand real world practical solutions, modern too... options. Assume I'm making a site like Wix, so I might use stuff like grapeJS and 3D junk.
Ruling out some options: 1. _*JS treated as static resources in ktor*_: keep coming back to this, but question testing and other stuff (like why my HTML and CSS is considered src but JS isn't, lol. 2. _*multiplatform w KotlinJS*_: doesn't play well with other plugins I found, trying to avoid it (I moved to gradle subprojects and I am happier, but even there I find many frameworks can't handle it, e.g. liferay). 3. _*React/angular/Equivalent + Ktor Gradle subprojects*: Good Example; What I was considering, maybe angularJS instead of React, I have more experience with it. A_lthough I'm not really sure what this buys you that using the ktor resources folder for housing JS wouldn't get you (thinking tooling and development speed). 4. 'Ktor Backend' + 'Ktor CSS/HTML & KotlinJS Frontend' as Gradle subprojects: not sure that's possible, if it were I should be able to combine backend and front end better. I think KotlinJS only plays well in an isolated multiplatform project or and isolated KotlinJS project.
r
I've created some large fullstack apps with KVision and in my opinion Kotlin/JS works fine in MPP configuration if you have good configuration to workaround some nasty bugs. I'm using Spring backend but it should work fine with Ktor, too.
g
hmm.... Kvision; I forgot about this one, don't know much about it either. I'll dig into it a little. Would this be part of the same ktor project or could/should it be a gradle subproject?
r
If you want to write your frontend code in Kotlin, you don't really have a lot options. You can use KVision, React-Kotlin from JB, probably also experiment with Fritz2 or Kweb.
If you don't want/need Kotlin, you can of course use anything you wish (Angular, Vue, Svelte, whatever you know best)
g
I'm not sure, maybe I should stick with classical JS/HTML/CSS... but even then I'm not sure how to go about the best way to develop and serve that up
r
g
Yeah... I'm staying away from multiplatform plugin for sure. Bottom line: I have the strong impression I love gradle but hate gradle plugins, mostly because of my time with multiplatform and trying to make that work with other plugins... stuff is getting too opinionated, doesn't work with other stuff and many opinions seem illogical.
r
I agree, It's hard to make MPP work with some other stuff. Last week I've spend whole two days to integrate MPP with Micronaut, because I haven't found any working example of MPP with Kapt and Kotlin Gradle DSL.
But with some effort it's possible ;-)
g
Gradle subprojects, honestly work better... but still, frameworks are opinionated and even that fails. So yeah... I think an opinionated ktor and isolated JS is what I'll do, angularJS. Still not sure the best way to serve that up with ktor.
r
But sharing common Kotlin code between frontend and backend is worth this effort.
g
sure gradle subproject could handle it... common code = library IMHO
r
MPP with gradle subprojects have other issues as well.
g
image.png
What am I doing wrong here, or what's the url to get it?
I think I can do all else if I get this, lol
r
you want
/web/static/index.html
to work?
g
I wanna serve up my first html, js and css... index page...
yeah that route is fine
r
have you tried
resources("web")
instead of
files("web")
?
I'm using this kind of configuration:
Copy code
routing {
        static("/") {
            resources("assets")
            defaultResource("assets/index.html")
        }
    }
g
okay, this helps... starting to get some working statics. just a sec
Nice, I like this. I couldn't figure out how to set the default page... i.e. forward all random URLs to it, thought defaultResource would work but wrong.
Copy code
static("/") {
    resources("web")
    defaultResource("web/index.html")
}
This does work for serving up my first file in a comprehendable way... will be curious to see what happens when I package this up in jars and wars using some other gradle plugin ,lol
r
works fine when building fat jar with resources inside the package
but I haven't tried ktor with war packaging
g
Cool. So now I can just program in my resources folder with HTML/CSS/JS... still gotta figure out running tests on that stuff (HTML/JS/CSS), or maybe not. I can't seem to stop thinking like devOps engineer.
I guess jest is the solution there, so it really is all development in the browser... like the old days!
Thanks for the help, one word might have cost me 3 days 😃
Yeah... I did get a JS/JVM/Ktor multiplatofrm project working... but it took a month, had too many holes fixed with duck tape and super glue and was still partly broken (e.g. silly run warnings or wrrors, partly broken gradle tasks). I remember webpack was a nightmare, had to open a ticket and be given a workaround.
s
`I heard KotlinJS isn't really being developed or might be retired`How did you hear about this?
g
Honestly I don't recall, may have been an obscure comment on a thread somewhere... I feel like I've read them all by now, lol, 8 years back
d
I've just had an extremely positive experience with Ktor + Kotlin/JS full-stack in recent days.
Not a web developer at all, but I was given a web task as a recruitment challenge and tackled it with this stack ...never used it before, worked admirably.
Was rapt when coroutines 'just worked' in transpiled JS and I could use Flows to process UI interactions.
I also haven't heard anything about Kotlin/JS being deprecated - calling FUD on this.
Though it does seem likely that Kotlin/JS will ultimately become just a stepping stone on the way to the new Kotlin/WASM support. Once this is eventually polished, it feels like there'd be little reason for /JS to exist.
g
I do see the potential of Kotlin, it's being developed in a way that could make it definitive... but it needs a lot of work. There should be more than one way to compile to multiplatform, I should be able to drop a function anywhere "Program(from="Kotlin", to="Pascal", compile=true, transpile=true) { } anywhere, with any language... that's multiplatform, lol. Plus Kotlin is still more wordy than python. I essentially have multiplatform working now, except I'm using gradle subprojects instead of the multiplatform plugin... I did get multiplatform working reasonably well, but as soon as I tried to walk outside the pardigm of the plugin while staying in the paradigm of gradle it broke.
Is this how you startyou KotlinJS programs? Seems to make sense, saw there where 4 things associated with the browser object, socument and window are 2. Trying to understand what a larger architecture would look like, if there are other considerations. Anyone got a good large KotlinJS example:
Copy code
fun main() {
    document.addEventListener("DOMContentLoaded", {