anybody has some experience with react and ktor? o...
# ktor
m
anybody has some experience with react and ktor? or some other frameworks or technologies for people like me who don’t really know JS?
b
i use ktor in combination with vue (atm ktor also serves the generated vue stuff, but in theory it should be easily movable to a CDN)
what i do is .. in my gradle build i build the JS stuff before building the backend stuff and package it in a fatJar .. works well so far
m
oh OK
did you try not packing anything in a JAR?
b
i did it for convenience .. as i said .. it should work without it too
there is no reason it shouldn't .. when the whole crossorigin request stuff is handled correctly with dns
m
to be honest I don’t know where to begin with 😞
b
my personal experience with Vue .. it's a monster with a very steep learning curve. i don't know how react compares to it .. if you are a "beginner" it's probably easier to just start with plain html/js? i try to avoid frontend stuff where possible, so i am just running it for my fun projects
m
yes, that’s what I thought, but I dislike freemarker and i don’t have an ultimate intellij license
b
my first projects where just plain html with a bit of jquery code .. was also ok but tbh i don't know what to recommend 🙂
m
well I know some react and would like to keep learning.
it’s just that I don’t know where to start with
b
m
yep
b
Setup a multiplatform project with ktor on the backend and react on frontend. then in ktor just serve react app as static resource
m
interesting
b
m
one important question: I already know some serious react syntax, components etc
can I use that in a project, without having to do the frontend in Kotlin, just the backend?
b
What do you mean? As in you have the frontend already?
If so, then just put all the frontend in frontendMain/resources/WEB-INF and it'll serve those with the example setup above
m
using the bootstrap you mean right?
yes, let’s imagine I already have the react components
or for example, I have here an already full stack project working, but it uses FreeMarker; I’d like to rewrite the frontend in React
b
Essentially all you want to do is serve static resources from ktor. Now whether they're kotlin compiled to js or an existing webpack bundle, it does not matter
Then use MPP setup from above and add existing plain-js components as resources for kotlin js-interop
However this already sounds messy, so I'd strongly recommend converting them to kotlin
rewriting*
It's not that much different, really
m
well not exactly, because the Freemarker I have also has some params to be passed to the template, such as with
Copy code
call.respond(FreeMarkerContent("signin.ftl", mapOf("userId" to signin.userId, "error" to signin.error)))