https://kotlinlang.org logo
#ktor
Title
# ktor
m

Manuel Lorenzo

09/16/2019, 1:42 PM
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

bitkid

09/16/2019, 1:46 PM
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

Manuel Lorenzo

09/16/2019, 1:53 PM
oh OK
did you try not packing anything in a JAR?
b

bitkid

09/16/2019, 2:08 PM
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

Manuel Lorenzo

09/16/2019, 2:09 PM
to be honest I don’t know where to begin with 😞
b

bitkid

09/16/2019, 2:10 PM
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

Manuel Lorenzo

09/16/2019, 2:12 PM
yes, that’s what I thought, but I dislike freemarker and i don’t have an ultimate intellij license
b

bitkid

09/16/2019, 2:16 PM
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

Manuel Lorenzo

09/16/2019, 2:19 PM
well I know some react and would like to keep learning.
it’s just that I don’t know where to start with
b

bitkid

09/16/2019, 2:20 PM
m

Manuel Lorenzo

09/16/2019, 2:20 PM
yep
b

Big Chungus

09/16/2019, 2:30 PM
Setup a multiplatform project with ktor on the backend and react on frontend. then in ktor just serve react app as static resource
m

Manuel Lorenzo

09/16/2019, 2:32 PM
interesting
b

Big Chungus

09/16/2019, 2:32 PM
m

Manuel Lorenzo

09/16/2019, 2:33 PM
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

Big Chungus

09/16/2019, 2:34 PM
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

Manuel Lorenzo

09/16/2019, 2:36 PM
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

Big Chungus

09/16/2019, 2:37 PM
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

Manuel Lorenzo

09/16/2019, 2:40 PM
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)))
2 Views