varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.53k stars 68 forks source link

Epic: Allow Kobweb to work in cases where it doesn't own the server #22

Open bitspittle opened 3 years ago

bitspittle commented 3 years ago

To check off items on this list, they should both be supported AND documented

Static support

These items probably just need files to be exported a certain way

Dynamic support

These items probably need logic currently backed into the kobweb/backend codebase refactored out into a shareable JVM library and then implemented per target

Other

I'm not familar with these technologies at this point so they will require a bit more investigation to categorize / understand properly


Original comment:

Feedback from the community: "end to end does provide a better headstart experience. but afaik backend is super complex so integrating it w/ something like spring boot would make it a lot more feasible for many use cases"

bitspittle commented 1 year ago

Note that a "workaround" for people running their own servers is to serve the Kobweb site themselves.

NorbertSandor commented 4 months ago

I already use Kobweb on the client side - it is great :) It would be nice if I could use live reloading support during development but also be able to use my Ktor-based backend which I cannot (and don't want to) replace.

bitspittle commented 4 months ago

@NorbertSandor hey, since you have a real case, I have a question for you. If I allowed you to set up my Kobweb server to act as a proxy for your server, would that work for you?

Getting live reloading to work for your custom server probably won't ever happen (getting it right takes a fair bit of custom code, see here which if you dig in does some fancy classloader tricks and makes some assumptions).

That said, if I add proxy support to Kobweb servers, you could start up a Kobweb server and ALSO spin up your custom server, and have Kobweb configured to point at it.

If you rebuild / restart your server, then you kind of get a live reloading experience, as the existing Kobweb server will just keep delegating to whatever is running.

NorbertSandor commented 4 months ago

set up my Kobweb server to act as a proxy for your server

This is how I currently use the Webpack Devserver:

So currently my Kotlin/JS webapp communicates directly only with the Devserver. It means I currently spin up 2 servers during development - and I have no problem with it :).

live reloading to work for your custom server probably won't ever happen

I see... The reason I want to give a try to Kobweb (besides that I already use the Modifier-system and other lower-level features) is that I'm not satisfied with how the Kotlin - Webpack Devserver integration works (or often not works in my case). I have already tried the generated "hello-world" Kobweb project but I want to try somehow how it would work with my complex multi-project application.

That said, if I add proxy support to Kobweb servers, you could start up a Kobweb server and ALSO spin up your custom server

This is exactly how I currently use the Webpack Devserver. It proxies everything to my backend except the generated JS files. So yes, it would probably work.

Just one question: wouldn't it be really big work to implement a HTTP+WS proxy from stratch? Or do you know a (Ktor-based) ready-to-integrate alternative?

Another idea has just popped in my head, namely to avoid HTTP/WS proxying entirely:

  1. I could refactor my Kotlin/JS webapp to call my backend directly instead of letting the Webpack Devserver to proxy my connections.
  2. Then I will try to convert the webapp to Kobweb (and replace Webpack-related Gradle tasks like jsBrowserDevelopmentRun with Kobweb tasks).

If I allowed you to set up my Kobweb server to act as a proxy for your server

The reason I don't want you to implement this proxying functionality right now is because I'm not sure that I can successfully convert my app to Kobweb, and I don't want you to work unnecessarily. It is because my biggest problem is not the proxying: my webapp owns the entire application logic, starting from a suspend main() function (it starts a DI container, makes various initializations, etc.), so it will be probably non-trivial to convert it to Kobweb - I don't know if I can do it at all :( (so currently I'm just collecting information about all related tasks, before even starting this huge refactoring).

But thanks for the insights, and giving me the above idea :)