Skip to content

Commit

Permalink
chore: update axum to 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
getong committed Jan 13, 2025
1 parent 45bb0dd commit 751f66f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 5 additions & 6 deletions crates/tuono_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ include = [


[dependencies]
ssr_rs = "0.7.0"
axum = {version = "0.7.5", features = ["json", "ws"]}
axum-extra = {version = "0.9.6", features = ["cookie"]}
ssr_rs = "0.8"
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"
Expand All @@ -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"

15 changes: 11 additions & 4 deletions crates/tuono_lib/src/vite_websocket_proxy.rs
Original file line number Diff line number Diff line change
@@ -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/";
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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())
}
};

Expand Down

0 comments on commit 751f66f

Please sign in to comment.