2022-06-24 18:06:04 +00:00
|
|
|
#![cfg(feature = "axum")]
|
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
|
2022-04-24 02:13:43 +00:00
|
|
|
use dioxus_core::{Element, LazyNodes, Scope};
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-06-20 06:24:39 +00:00
|
|
|
pretty_env_logger::init();
|
2022-04-24 02:13:43 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
|
2022-04-24 02:13:43 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
let view = dioxus_liveview::new(addr);
|
|
|
|
let body = view.body("<title>Dioxus Liveview</title>");
|
2022-04-24 02:13:43 +00:00
|
|
|
|
2022-06-20 06:24:39 +00:00
|
|
|
let app = Router::new()
|
|
|
|
.route("/", get(move || async { Html(body) }))
|
|
|
|
.route(
|
|
|
|
"/app",
|
|
|
|
get(move |ws: WebSocketUpgrade| async move {
|
|
|
|
ws.on_upgrade(move |socket| async move {
|
|
|
|
view.upgrade_axum(socket, app).await;
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
axum::Server::bind(&addr.to_string().parse().unwrap())
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-04-24 02:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!"))))
|
|
|
|
}
|