Hey everyone, I’m just looking for some advice on ...
# server
m
Hey everyone, I’m just looking for some advice on how to set up this project I’m working on. I need to stand up a server with an exposed API other applications can hit, with a front end gui that users can interact with. In addition to being able to deploy this as a server on VM, I need to be able to package the whole thing as a standalone application users can run locally on windows, linux, and osx when they don’t have access to the internet. I was thinking of using ktor as the back end and kotlin js for the front end, but I want to make sure I’m setting the project up correctly. If I use the default Kotlin ->
JS Client and JVM Server | Gradle
new project setup in IntelliJ, will this provide the project structure necessary for these requirements? Or is there a better starter project to use? Also, has anyone had experience doing this kind of dual purpose project? One that needs to be deployed as a stand-alone server with a front end, and also needs to be packaged as an application that can be run locally without internet? Any advice would be greatly appreciated. I think I have a good idea on where to start after reading though a bunch of the documentation, I just want to make sure I’m not missing anything.
g
I am working on something kinda similar, actually. Have you looked into KTOR? https://ktor.io/ Really easy way to build a server in Kotlin, and you can bundle it as an executable jar. You can bundle a browser based front end with it.
m
Yeah! I did look at it, and was messing around with the demos. If I do a Kotlin/JS front end, as part of the kotor project, will it still be as simple as packaging as a jar to distribute as an executable? I'm looking for the same kind of feel as an Electron app, ie I want users to feel like the standalone app is an actual application, not a tab in their web browser
g
yeah I was about to suggest electron as an alternative. I think the way I suggested would definitely lean towards users opening a browser. If you do go the .jar route, you could bundle a Java based front-end, which would definitely feel more like a native app
we've used https://tornadofx.io/ in the past
our devs love it
m
Yeah, I only want to write the front end once, in JS and then have it look identical in the app and as a webpage when people access the server through their browser. I think electron might be the way to go. Do you know of any examples of people using Electron with a Ktor project?
Is it even possible?
g
ktor servers cant run on JS yet, but you could use kotlin to wrap express.js for the server part
entirely possible, maybe a pain in the butt
m
Okay, thanks. I'm probably going to start with a ktor project and see what it feels like booting the whole thing as a jar, and then go from there. Thanks for the guidance on this.
g
no worries, and actually - looks like you may be able to get the best of both worlds: https://medium.com/@daniel.bischoff/integrating-chromium-as-a-web-renderer-in-a-java-application-with-jcef-72f67a677db6
m
Oh, that's interesting
thanks
j
You can also embed a browser with JavaFX using TornadoFX
g
oh nice!
j
You can find an example here:
It embeds a CodeMirror or Ace editor component in a JavaFX application
m
Hey Thanks! I'll take a look
j
If you have any problem running it, you can contact me. I’m developing it… Good luck!
j
Spring boot with Expedia's Kotlin graphql integration is a nice alternative to ktor. And it comes with a playground UI. I was playing with this a few days ago. You can even generate API clients from the graphql schema. Otherwise, I would not mix UI and backend code in one project and keep them separated. Kotlin-js is very immature still so I would consider that a risk. It kind of works but you are kind of on your own figuring things out.