mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-22 02:23:05 +00:00
d9546d9504
* feat: use synchronous router design * feat: function to get router out of dom * chore: restructure workspace to use renderers as packages, not features
35 lines
1 KiB
Rust
35 lines
1 KiB
Rust
#[cfg(not(feature = "warp"))]
|
|
fn main() {}
|
|
|
|
#[cfg(feature = "warp")]
|
|
#[tokio::main]
|
|
async fn main() {
|
|
use dioxus_core::{Element, LazyNodes, Scope};
|
|
use dioxus_liveview as liveview;
|
|
use warp::ws::Ws;
|
|
use warp::Filter;
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!"))))
|
|
}
|
|
|
|
pretty_env_logger::init();
|
|
|
|
let addr = ([127, 0, 0, 1], 3030);
|
|
|
|
// todo: compactify this routing under one liveview::app method
|
|
let view = liveview::new(addr);
|
|
let body = view.body("<title>Dioxus LiveView</title>");
|
|
|
|
let routes = warp::path::end()
|
|
.map(move || warp::reply::html(body.clone()))
|
|
.or(warp::path("app")
|
|
.and(warp::ws())
|
|
.and(warp::any().map(move || view.clone()))
|
|
.map(|ws: Ws, view: liveview::Liveview| {
|
|
ws.on_upgrade(|socket| async move {
|
|
view.upgrade_warp(socket, app).await;
|
|
})
|
|
}));
|
|
warp::serve(routes).run(addr).await;
|
|
}
|