integrate liveview with the launch builder

This commit is contained in:
Evan Almloff committed 2024-01-22 11:56:34 -06:00
1 parent 50873bf9c7
commit 636aeb4b90
20 files changed
+443 -97

No files matched your search

+3 -39
View File
@@ -1,5 +1,6 @@
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
use axum::Router;
use dioxus::prelude::*;
use dioxus_liveview::LiveviewRouter;
fn app() -> Element {
let mut num = use_signal(|| 0);
@@ -18,44 +19,7 @@ async fn main() {
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
let view = dioxus_liveview::LiveViewPool::new();
let index_page_with_glue = |glue: &str| {
Html(format!(
r#"
<!DOCTYPE html>
<html>
<head> <title>Dioxus LiveView with axum</title> </head>
<body> <div id="main"></div> </body>
{glue}
</html>
"#,
))
};
let app =
Router::new()
.route(
"/",
get(move || async move {
index_page_with_glue(&dioxus_liveview::interpreter_glue(&format!(
"ws://{addr}/ws"
)))
}),
)
.route(
"/as-path",
get(move || async move {
index_page_with_glue(&dioxus_liveview::interpreter_glue("/ws"))
}),
)
.route(
"/ws",
get(move |ws: WebSocketUpgrade| async move {
ws.on_upgrade(move |socket| async move {
_ = view.launch(dioxus_liveview::axum_socket(socket), app).await;
})
}),
);
let app = Router::new().with_app("/", app);
println!("Listening on http://{addr}");
+1 -1
View File
@@ -36,7 +36,7 @@ async fn main() {
}
#[handler]
fn index(_depot: &mut Depot, res: &mut Response) {
fn index(res: &mut Response) {
let addr: SocketAddr = ([127, 0, 0, 1], 3030).into();
res.render(Text::Html(format!(
r#"
+1 -1
View File
@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use dioxus_liveview::adapters::warp_adapter::warp_socket;
use dioxus_liveview::warp_adapter::warp_socket;
use dioxus_liveview::LiveViewPool;
use std::net::SocketAddr;
use warp::ws::Ws;