Skip to content

Commit

Permalink
build: update axum
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Dec 2, 2023
1 parent 38f6a1d commit e2b0dfe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions examples/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ path = "src/webserver.rs"
anyhow = "1.0.57"
serde = "1.0.136"
serde_json = "1.0.79"
axum = { version = "0.7.1", features = ["ws"] }
futures = "0.3.21"
log = "0.4.16"
async-trait = "0.1.53"
typescript-type-def = { version = "0.5.3", features = ["json_value"] }
async-broadcast = "0.4.0"
yerpc = { path = "../../yerpc", features = ["anyhow", "support-axum"]}
axum = { version = "0.6.6", features = ["ws"] }
tokio = { version = "1.19.2", features = ["full"] }
tower-http = { version = "0.5.0", features = ["trace"] }
tracing = "0.1.35"
tracing-subscriber = "0.3.11"
tower-http = { version = "0.3.0", features = ["trace"] }
schemars = "0.8.11"
yerpc = { path = "../../yerpc", features = ["anyhow", "support-axum"]}
6 changes: 2 additions & 4 deletions examples/axum/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ async fn main() -> Result<(), std::io::Error> {
.layer(Extension(backend));
let addr = SocketAddr::from(([127, 0, 0, 1], 20808));
println!("listening on {addr}");
axum::Server::bind(&addr)
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await
.unwrap();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();

Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions yerpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ schemars = { version = "0.8.11", optional = true }

# optional dependencies
anyhow = { version = "1.0.57", optional = true }
axum = { version = "0.6.6", features = ["ws"], optional = true }
tokio-tungstenite = { version = "0.17", optional = true }
axum = { version = "0.7.1", features = ["ws"], optional = true }
tokio-tungstenite = { version = "0.20", optional = true }
tokio = { version = "1.19.2", features = ["rt", "macros"], optional = true }
tracing = { version = "0.1.35", optional = true }

Expand All @@ -45,7 +45,7 @@ openrpc = ["schemars", "yerpc_derive/openrpc"]

[dev-dependencies]
anyhow = "1.0.57"
axum = { version = "0.6.6", features = ["ws"] }
tokio-tungstenite = { version = "0.17" }
axum = { version = "0.7.1", features = ["ws"] }
tokio-tungstenite = { version = "0.20" }
tokio = { version = "1.19.2", features = ["rt", "macros"] }
url = "2.2.2"
10 changes: 4 additions & 6 deletions yerpc/tests/axum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(all(test, feature = "support-axum", feature = "support-tungstenite"))]
mod tests {
use axum::{
extract::ws::WebSocketUpgrade, http::StatusCode, response::Response, routing::get, Router,
};
use axum::{extract::ws::WebSocketUpgrade, response::Response, routing::get, Router};
use futures_util::{SinkExt, StreamExt};
use std::net::SocketAddr;
use tokio::net::TcpStream;
use tokio_tungstenite::client_async;
use tokio_tungstenite::tungstenite::http::StatusCode;
use tokio_tungstenite::tungstenite::Message;
use yerpc::axum::handle_ws_rpc;
use yerpc::tungstenite::tungstenite_client;
Expand Down Expand Up @@ -41,10 +40,9 @@ mod tests {
async fn test_axum_websocket() -> anyhow::Result<()> {
let app = Router::new().route("/rpc", get(handler));
let addr = SocketAddr::from(([127, 0, 0, 1], 12345));
let listener = std::net::TcpListener::bind(addr).unwrap();
let server = axum::Server::from_tcp(listener).unwrap();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
tokio::spawn(async move {
server.serve(app.into_make_service()).await.unwrap();
axum::serve(listener, app).await.unwrap();
});

let tcp = TcpStream::connect("127.0.0.1:12345")
Expand Down

0 comments on commit e2b0dfe

Please sign in to comment.