fix the fullstack platform with the new launch API
This commit is contained in:
1 parent
cb5a43c120
commit
a323962a22
7 files changed
+281
-255
No files matched your search
@@ -63,7 +63,8 @@ use axum::{
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use dioxus_lib::prelude::dioxus_core::{AnyProps, CrossPlatformConfig};
|
||||
use dioxus_lib::prelude::dioxus_core::AnyProps;
|
||||
use dioxus_lib::prelude::VirtualDom;
|
||||
use server_fn::{Encoding, ServerFunctionRegistry};
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
@@ -216,11 +217,11 @@ pub trait DioxusRouterExt<S> {
|
||||
/// todo!()
|
||||
/// }
|
||||
/// ```
|
||||
fn serve_dioxus_application<P: AnyProps + Clone + Send + Sync + 'static>(
|
||||
fn serve_dioxus_application(
|
||||
self,
|
||||
server_fn_route: &'static str,
|
||||
cfg: impl Into<ServeConfig>,
|
||||
dioxus_config: CrossPlatformConfig<P>,
|
||||
build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
@@ -315,11 +316,11 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn serve_dioxus_application<P: AnyProps + Clone + Send + Sync + 'static>(
|
||||
fn serve_dioxus_application(
|
||||
self,
|
||||
server_fn_route: &'static str,
|
||||
cfg: impl Into<ServeConfig>,
|
||||
dioxus_config: CrossPlatformConfig<P>,
|
||||
build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
let cfg = cfg.into();
|
||||
let ssr_state = SSRState::new(&cfg);
|
||||
@@ -328,7 +329,7 @@ where
|
||||
self.serve_static_assets(cfg.assets_path)
|
||||
.connect_hot_reload()
|
||||
.register_server_fns(server_fn_route)
|
||||
.fallback(get(render_handler).with_state((cfg, dioxus_config, ssr_state)))
|
||||
.fallback(get(render_handler).with_state((cfg, Arc::new(build_virtual_dom), ssr_state)))
|
||||
}
|
||||
|
||||
fn connect_hot_reload(self) -> Self {
|
||||
@@ -418,15 +419,12 @@ fn apply_request_parts_to_response<B>(
|
||||
/// .unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn render_handler_with_context<
|
||||
P: AnyProps + Clone + Send + Sync + 'static,
|
||||
F: FnMut(&mut DioxusServerContext),
|
||||
>(
|
||||
State((mut inject_context, cfg, ssr_state, dioxus_config)): State<(
|
||||
pub async fn render_handler_with_context<F: FnMut(&mut DioxusServerContext)>(
|
||||
State((mut inject_context, cfg, ssr_state, virtual_dom_factory)): State<(
|
||||
F,
|
||||
ServeConfig,
|
||||
SSRState,
|
||||
CrossPlatformConfig<P>,
|
||||
Arc<dyn Fn() -> VirtualDom + Send + Sync>,
|
||||
)>,
|
||||
request: Request<Body>,
|
||||
) -> impl IntoResponse {
|
||||
@@ -437,7 +435,7 @@ pub async fn render_handler_with_context<
|
||||
inject_context(&mut server_context);
|
||||
|
||||
match ssr_state
|
||||
.render(url, &cfg, dioxus_config, &server_context)
|
||||
.render(url, &cfg, move || virtual_dom_factory(), &server_context)
|
||||
.await
|
||||
{
|
||||
Ok(rendered) => {
|
||||
@@ -456,12 +454,16 @@ pub async fn render_handler_with_context<
|
||||
}
|
||||
|
||||
/// SSR renderer handler for Axum
|
||||
pub async fn render_handler<P: AnyProps + Clone + Send + Sync + 'static>(
|
||||
State((cfg, dioxus_config, ssr_state)): State<(ServeConfig, CrossPlatformConfig<P>, SSRState)>,
|
||||
pub async fn render_handler(
|
||||
State((cfg, virtual_dom_factory, ssr_state)): State<(
|
||||
ServeConfig,
|
||||
Arc<dyn Fn() -> VirtualDom + Send + Sync>,
|
||||
SSRState,
|
||||
)>,
|
||||
request: Request<Body>,
|
||||
) -> impl IntoResponse {
|
||||
render_handler_with_context(
|
||||
State((|_: &mut _| (), cfg, ssr_state, dioxus_config)),
|
||||
State((|_: &mut _| (), cfg, ssr_state, virtual_dom_factory)),
|
||||
request,
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in new issue
Block a user