add proper error and disconnect handling
error handling shows you the error and offers the ability to reload; disconnect handling shows you that the page will reload in a few seconds. it uses exponential backoff with some random sprinkled into it to prevent overwhelming the server once people's clients decide to reconnect.
This commit is contained in:
parent
84abba3e0b
commit
0d831698e2
8 changed files with 150 additions and 20 deletions
|
@ -4,12 +4,17 @@ use axum::{routing::get, Router};
|
|||
use tokio::time::sleep;
|
||||
|
||||
pub fn router<S>() -> Router<S> {
|
||||
Router::new()
|
||||
.route("/stall", get(stall))
|
||||
.route("/back-up", get(back_up))
|
||||
.with_state(())
|
||||
let router = Router::new().route("/back-up", get(back_up));
|
||||
|
||||
// The endpoint for immediate reload is only enabled on debug builds.
|
||||
// Release builds use the exponential backoff system that detects is the WebSocket is closed.
|
||||
#[cfg(debug_assertions)]
|
||||
let router = router.route("/stall", get(stall));
|
||||
|
||||
router.with_state(())
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
async fn stall() -> String {
|
||||
loop {
|
||||
// Sleep for a day, I guess. Just to uphold the connection forever without really using any
|
||||
|
|
|
@ -18,7 +18,6 @@ mod api;
|
|||
mod config;
|
||||
mod haku;
|
||||
mod id;
|
||||
#[cfg(debug_assertions)]
|
||||
mod live_reload;
|
||||
mod login;
|
||||
pub mod schema;
|
||||
|
@ -102,8 +101,7 @@ async fn fallible_main() -> eyre::Result<()> {
|
|||
.nest_service("/static", ServeDir::new(paths.target_dir.join("static")))
|
||||
.nest("/api", api::router(api));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let app = app.nest("/dev/live-reload", live_reload::router());
|
||||
let app = app.nest("/auto-reload", live_reload::router());
|
||||
|
||||
let port: u16 = std::env::var("RKGK_PORT")
|
||||
.unwrap_or("8080".into())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue