Closed DarrienG closed 5 years ago
I think this may partially be on me. The Caddy websocket plugin needs to be installed to properly relay websocket connections. Going to try...
Edit - it's built in. I'm at a bit of a loss here.
You're on the right track with investigating the websocket connection. The "constant reloading" happens a lot when something isn't configured correctly, because if the bootstrap code fails to establish a ws for an unknown reason, it simply reloads the page. We could definitely use some better error handling here to check for common misconfiguration, and maybe a limit to the number of reloads before it gives up and shows an error.
Anyway, for your issue I would keep looking at your proxy. If you breakpoint the code just before it reloads (or change the devtool settings to preserve the console log), you can see the error message in the console:
WebSocket connection to 'wss://yakstack.dev/ws' failed: Error during WebSocket handshake: Unexpected response code: 200
It looks like the bootstrap is trying to open the websocket connection and the server (more likely the proxy) is returning a 200 status code, instead of the ws handshake. Another thing to note here is that because your site is https the bootstrap code is using wss:// instead of ws://. I don't have much experience with proxies and ssl and stuff so I can't give you any concrete pointers here, but I would keep looking in that area.
Agree with @ethanmdavidson re: the current reloading mechanism, it's a fairly blunt instrument right now and it should do exponential backoff and better error reporting.
If we find that dependence on WebSockets are a serious limitation we could provide an alternate transport (like long-polling HTTP), although I'd prefer to avoid that if possible.
I see. I'll take another look at my proxy config. In the meantime for mostly static webpages, is there a way to disable the need to a websocket connection? While perhaps out of the scope of this project, I would be ok if I could use kweb as a static website builder.
Update, I figured it out. You do have to enable websockets manually with caddy. For me, the configuration looks like this:
yakstack.dev {
proxy / localhost:9797 {
websocket
}
}
It would be handy to know this project uses websockets somewhere, but otherwise, works great now. Thanks guys :D
Thanks @DarrienG, glad to hear you got it working.
We do mention Kweb's use of websockets in How does it work?, do we need to make it more explicit?
Ah that's my bad. I somehow missed that portion. I guess how does it work almost feels like a section about implementation details rather than something I would need to know as a user.
With that said, it's pretty clear there it does use websockets. So I definitely should have read a little bit closer.
Thanks for all the support and Kweb, I appreciate it!
You're welcome! I created #69 to address at least one of the issues you raised, and will think more about whether I can make the user manual clearer. Please let us know if you have additional feedback.
Full project (it's pretty much just the fomatic plugin with a few divs, headers, and paragraphs.
When run locally (`./gradlew run) everything works as intended. When run hosted, (https://yakstack.dev) the site constantly reloads.
It seems like it's trying to get a websocket of some sort and is reloading again and again to get it.
A few details about hosting that might help - I'm using caddy as a reverse proxy to point to the site.
ufw
is set up to a very restrictive policy. I'm not certain if the generated site tries to call back via a different port and reload if it doesn't work. If it does, that will fail.