diff --git a/crates/tuono_lib/Cargo.toml b/crates/tuono_lib/Cargo.toml index 70569e81..01f074a3 100644 --- a/crates/tuono_lib/Cargo.toml +++ b/crates/tuono_lib/Cargo.toml @@ -18,8 +18,8 @@ include = [ [dependencies] ssr_rs = "0.8.0" -axum = {version = "0.7.5", features = ["json", "ws"]} -axum-extra = {version = "0.9.6", features = ["cookie"]} +axum = {version = "0.8", features = ["json", "ws"]} +axum-extra = {version = "0.10", features = ["cookie"]} tokio = { version = "1.37.0", features = ["full"] } serde = { version = "1.0.202", features = ["derive"] } erased-serde = "0.4.5" @@ -34,10 +34,9 @@ colored = "2.1.0" tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.17.0"} # Match the same version used by axum -tokio-tungstenite = "0.24.0" +tokio-tungstenite = "0.26" futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } -tungstenite = "0.24.0" +tungstenite = "0.26" http = "1.1.0" pin-project = "1.1.7" tower = "0.5.1" - diff --git a/crates/tuono_lib/src/server.rs b/crates/tuono_lib/src/server.rs index e7181132..46c8ad90 100644 --- a/crates/tuono_lib/src/server.rs +++ b/crates/tuono_lib/src/server.rs @@ -41,7 +41,7 @@ impl Server { .to_owned() .layer(LoggerLayer::new()) .route("/vite-server/", get(vite_websocket_proxy)) - .route("/vite-server/*path", get(vite_reverse_proxy)) + .route("/vite-server/{*path}", get(vite_reverse_proxy)) .fallback_service( ServeDir::new(DEV_PUBLIC_DIR) .fallback(get(catch_all).layer(LoggerLayer::new())), diff --git a/crates/tuono_lib/src/vite_websocket_proxy.rs b/crates/tuono_lib/src/vite_websocket_proxy.rs index 0dce599f..9cba5b7d 100644 --- a/crates/tuono_lib/src/vite_websocket_proxy.rs +++ b/crates/tuono_lib/src/vite_websocket_proxy.rs @@ -1,9 +1,10 @@ -use axum::extract::ws::{self, WebSocket, WebSocketUpgrade}; +use axum::extract::ws::{self, Utf8Bytes as AxumUtf8Bytes, WebSocket, WebSocketUpgrade}; use axum::response::IntoResponse; use futures_util::{SinkExt, StreamExt}; use tokio_tungstenite::connect_async; use tokio_tungstenite::tungstenite::{Error, Message}; use tungstenite::client::IntoClientRequest; +use tungstenite::protocol::frame::Utf8Bytes; use tungstenite::ClientRequestBuilder; const VITE_WS: &str = "ws://localhost:3001/vite-server/"; @@ -54,7 +55,10 @@ async fn handle_socket(mut tuono_socket: WebSocket) { while let Some(msg) = tuono_receiver.next().await { if let Ok(msg) = msg { let msg_to_vite = match msg.clone() { - ws::Message::Text(str) => Message::Text(str), + ws::Message::Text(str) => { + let str = str.as_str().to_string(); + Message::Text(Utf8Bytes::from(str)) + } ws::Message::Pong(payload) => Message::Pong(payload), ws::Message::Ping(payload) => Message::Ping(payload), ws::Message::Binary(payload) => Message::Binary(payload), @@ -81,7 +85,10 @@ async fn handle_socket(mut tuono_socket: WebSocket) { tokio::spawn(async move { while let Some(Ok(msg)) = vite_receiver.next().await { let msg_to_browser = match msg { - Message::Text(str) => ws::Message::Text(str), + Message::Text(str) => { + let str = str.as_str().to_string(); + ws::Message::Text(AxumUtf8Bytes::from(str)) + } Message::Ping(payload) => ws::Message::Ping(payload), Message::Pong(payload) => ws::Message::Pong(payload), Message::Binary(payload) => ws::Message::Binary(payload), @@ -90,7 +97,7 @@ async fn handle_socket(mut tuono_socket: WebSocket) { Message::Close(_) => ws::Message::Close(None), _ => { eprintln!("Unexpected message from the vite WebSocket to the browser: {msg:?}"); - ws::Message::Text("Unhandled".to_string()) + ws::Message::Text("Unhandled".to_string().into()) } };