fix: salvo and remove actix from list of webframeworks

This commit is contained in:
Jonathan Kelley committed 2022-12-19 15:29:20 -08:00
1 parent 91233aa73a
commit b76c520108
5 files changed
+59 -77

No files matched your search

+26 -20
View File
@@ -13,45 +13,51 @@ license = "MIT/Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tokio = { version = "1", features = ["full"] } tokio = { version = "1.23.0", features = ["full"] }
futures-util = { version = "0.3", default-features = false, features = [ futures-util = { version = "0.3.25", default-features = false, features = [
"sink", "sink",
] } ] }
futures-channel = { version = "0.3.17", features = ["sink"] } futures-channel = { version = "0.3.25", features = ["sink"] }
pretty_env_logger = "0.4" pretty_env_logger = "0.4.0"
tokio-stream = { version = "0.1.1", features = ["net"] } tokio-stream = { version = "0.1.11", features = ["net"] }
serde = { version = "1.0.136", features = ["derive"] } serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.79" serde_json = "1.0.91"
tokio-util = { version = "0.7.0", features = ["full"] } tokio-util = { version = "0.7.4", features = ["full"] }
dioxus-html = { path = "../html", features = ["serialize"], version = "^0.2.1" } dioxus-html = { path = "../html", features = ["serialize"], version = "^0.2.1" }
dioxus-core = { path = "../core", features = ["serialize"], version = "^0.2.1" } dioxus-core = { path = "../core", features = ["serialize"], version = "^0.2.1" }
dioxus-interpreter-js = { path = "../interpreter" } dioxus-interpreter-js = { path = "../interpreter" }
# warp # warp
warp = { version = "0.3", optional = true } warp = { version = "0.3.3", optional = true }
# axum # axum
axum = { version = "0.5.1", optional = true, features = ["ws"] } axum = { version = "0.6.1", optional = true, features = ["ws"] }
tower = { version = "0.4.12", optional = true } tower = { version = "0.4.13", optional = true }
# salvo # salvo
salvo = { version = "0.32.0", optional = true, features = ["ws"] } salvo = { version = "0.37.7", optional = true, features = ["ws"] }
thiserror = "1.0.37" thiserror = "1.0.38"
uuid = { version = "1.2.2", features = ["v4"] } uuid = { version = "1.2.2", features = ["v4"] }
anyhow = "1.0.66" anyhow = "1.0.68"
# actix is ... complicated?
# actix-files = { version = "0.6.2", optional = true }
# actix-web = { version = "4.2.1", optional = true }
# actix-ws = { version = "0.2.5", optional = true }
[dev-dependencies] [dev-dependencies]
tokio = { version = "1", features = ["full"] } tokio = { version = "1.23.0", features = ["full"] }
dioxus = { path = "../dioxus" } dioxus = { path = "../dioxus" }
warp = "0.3" warp = "0.3.3"
axum = { version = "0.5.1", features = ["ws"] } axum = { version = "0.6.1", features = ["ws"] }
salvo = { version = "0.32.0", features = ["affix", "ws"] } salvo = { version = "0.37.7", features = ["affix", "ws"] }
tower = "0.4.12" tower = "0.4.13"
[features] [features]
default = ["salvo"] default = []
# actix = ["actix-files", "actix-web", "actix-ws"]
[[example]] [[example]]
name = "axum" name = "axum"
+1 -47
View File
@@ -1,49 +1,3 @@
# Dioxus LiveView # Dioxus LiveView
Enabling server-rendered and hybrid applications with incredibly low latency (<1ms). Server rendered apps with minimal latency
```rust
#[async_std::main]
async fn main() -> tide::Result<()> {
let liveview_pool = dioxus::liveview::pool::default();
let mut app = tide::new();
// serve the liveview client
app.at("/").get(dioxus::liveview::liveview_frontend);
// and then connect the client to the backend
app.at("/app").get(|req| dioxus::liveview::launch(App, Props { req }))
app.listen("127.0.0.1:8080").await?;
Ok(())
}
```
Dioxus LiveView runs your Dioxus apps on the server
```rust
use soyuz::prelude::*;
#[tokio::main]
async fn main() {
let mut app = soyuz::new();
app.at("/app").get(websocket(handler));
app.listen("127.0.0.1:8080").await.unwrap();
}
async fn order_shoes(mut req: WebsocketRequest) -> Response {
let stream = req.upgrade();
dioxus::liveview::launch(App, stream).await;
}
fn App(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
cx.render(rsx!(
button { onclick: move |_| count += 1, "Incr" }
button { onclick: move |_| count -= 1, "Decr" }
))
}
```
+5 -9
View File
@@ -1,7 +1,6 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_liveview::LiveViewPool; use dioxus_liveview::LiveViewPool;
use salvo::extra::affix; use salvo::affix;
use salvo::extra::ws::WsHandler;
use salvo::prelude::*; use salvo::prelude::*;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::Arc; use std::sync::Arc;
@@ -58,13 +57,10 @@ async fn connect(
res: &mut Response, res: &mut Response,
) -> Result<(), StatusError> { ) -> Result<(), StatusError> {
let view = depot.obtain::<Arc<LiveViewPool>>().unwrap().clone(); let view = depot.obtain::<Arc<LiveViewPool>>().unwrap().clone();
let fut = WsHandler::new().handle(req, res)?;
tokio::spawn(async move { WebSocketUpgrade::new()
if let Some(ws) = fut.await { .upgrade(req, res, |ws| async move {
_ = view.launch(dioxus_liveview::salvo_socket(ws), app).await; _ = view.launch(dioxus_liveview::salvo_socket(ws), app).await;
} })
}); .await
Ok(())
} }
@@ -1,5 +1,5 @@
use futures_util::{SinkExt, StreamExt}; use futures_util::{SinkExt, StreamExt};
use salvo::extra::ws::{Message, WebSocket}; use salvo::ws::{Message, WebSocket};
use crate::{LiveViewError, LiveViewSocket}; use crate::{LiveViewError, LiveViewSocket};
+26
View File
@@ -46,6 +46,32 @@ impl LiveViewPool {
} }
/// A LiveViewSocket is a Sink and Stream of Strings that Dioxus uses to communicate with the client /// A LiveViewSocket is a Sink and Stream of Strings that Dioxus uses to communicate with the client
///
/// Most websockets from most HTTP frameworks can be converted into a LiveViewSocket using the appropriate adapter.
///
/// You can also convert your own socket into a LiveViewSocket by implementing this trait. This trait is an auto trait,
/// meaning that as long as your type implements Stream and Sink, you can use it as a LiveViewSocket.
///
/// For example, the axum implementation is a really small transform:
///
/// ```rust, ignore
/// pub fn axum_socket(ws: WebSocket) -> impl LiveViewSocket {
/// ws.map(transform_rx)
/// .with(transform_tx)
/// .sink_map_err(|_| LiveViewError::SendingFailed)
/// }
///
/// fn transform_rx(message: Result<Message, axum::Error>) -> Result<String, LiveViewError> {
/// message
/// .map_err(|_| LiveViewError::SendingFailed)?
/// .into_text()
/// .map_err(|_| LiveViewError::SendingFailed)
/// }
///
/// async fn transform_tx(message: String) -> Result<Message, axum::Error> {
/// Ok(Message::Text(message))
/// }
/// ```
pub trait LiveViewSocket: pub trait LiveViewSocket:
SinkExt<String, Error = LiveViewError> SinkExt<String, Error = LiveViewError>
+ StreamExt<Item = Result<String, LiveViewError>> + StreamExt<Item = Result<String, LiveViewError>>