2022-06-24 18:06:04 +00:00
|
|
|
#![cfg(feature = "warp")]
|
|
|
|
|
2022-03-15 05:02:44 +00:00
|
|
|
use dioxus_core::{Element, LazyNodes, Scope};
|
|
|
|
use dioxus_liveview as liveview;
|
|
|
|
use warp::ws::Ws;
|
|
|
|
use warp::Filter;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-06-20 06:24:39 +00:00
|
|
|
pretty_env_logger::init();
|
2022-03-15 05:02:44 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
let addr = ([127, 0, 0, 1], 3030);
|
2022-03-15 05:02:44 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
// todo: compactify this routing under one liveview::app method
|
|
|
|
let view = liveview::new(addr);
|
|
|
|
let body = view.body("<title>Dioxus LiveView</title>");
|
2022-03-15 05:02:44 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
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;
|
2022-03-15 05:02:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!"))))
|
|
|
|
}
|