-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: migrate serve WebSocket from ws crate to Axum #3048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
Migrates the live reload WebSocket server from the standalone `ws` crate to native Axum WebSocket support: - Replace ws::WebSocket with axum's built-in WebSocket extractor - Use tokio::sync::broadcast for message broadcasting to clients - Integrate WebSocket endpoint into main Axum router at /livereload - Serve livereload.js via dedicated route instead of fallback handler - Remove separate WebSocket server thread (now runs on same port as HTTP) Also fixes build error notification via WebSocket: - Send reload message on build errors so browser auto-refreshes - Handle 404 responses in error_injection_middleware for error display - Include livereload.js in error page so it can reload when fixed - Don't interfere with WebSocket upgrades (101) in middleware Additional improvements: - Add WebSocket ping/pong keepalive (30s interval) for connection health - Add graceful shutdown support via with_graceful_shutdown() - Handle Message::Close and Message::Pong explicitly in WebSocket handler - Remove unnecessary #[derive(Clone)] from AppState (already Arc-wrapped) Cleanup of vestigial ws_port code: - Remove ws_port parameter from create_new_site() function signature - Simplify enable_live_reload_with_port() to use interface_port directly - Update both call sites in serve() to remove the None argument - Update test helper to remove ws_port parameter - Fix test assertion to verify live_reload uses interface_port Dependencies: - Add "ws" feature to axum for WebSocket support - Add "sync" feature to tokio for broadcast channels - Remove ws, tower, tower-http, tracing, tracing-subscriber crates
|
I have a lot of work I'd like to do Zola. I'd like to add tracing for the webserver (so you can see when a response is sent). And I still really want to work that pipeline stuff in because I got a few killer features I'd like to publish as modules (namely compression, and encryption). If there anything I can do to make the turnaround on this faster, please tell me. What I'm aiming for is no controversy and easy value. (0 problem though, obviously this patch isn't 1 day old and I don't expect it to land in 24 hours). |
There's another PR to add logging that should cover the first part. 0.22 is mostly frozen right now in terms of feature, except small things like this PR or the logging one. The giallo change is a big one and I don't want to do a big release along with it. |
The patch provided doesn't use tracing. If you want tracing I could write you a better one. It was in my original PR too. Tracing would unify the logging and verbosity settings in You don't have to accept the compression and encryption patches (though I would -- why leave a killer feature like encryption behind), but even if not let's create a mdoular infrastructure that allows us to do things like html-templates/encryption/compression/Typst? Btw, the whole graceful shutdown is gone. we can add it back later if people want it. |

Migrates the live reload WebSocket server from the standalone
wscrate to native Axum WebSocket support:Also fixes build error notification via WebSocket:
Additional improvements:
Dependencies:
IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.
The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.
Sanity check:
Code changes
(Delete or ignore this section for documentation changes)
nextbranch?If the change is a new feature or adding to/changing an existing one: