|
@@ -177,6 +177,27 @@ pub trait DioxusRouterFnExt<S> {
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
/// ```
|
|
fn register_server_functions_with_context(self, context_providers: ContextProviders) -> Self;
|
|
fn register_server_functions_with_context(self, context_providers: ContextProviders) -> Self;
|
|
|
|
+
|
|
|
|
+ /// Serves a Dioxus application without static assets.
|
|
|
|
+ /// Sets up server function routes and rendering endpoints only.
|
|
|
|
+ ///
|
|
|
|
+ /// Useful for WebAssembly environments or when static assets
|
|
|
|
+ /// are served by another system.
|
|
|
|
+ ///
|
|
|
|
+ /// # Example
|
|
|
|
+ /// ```rust, no_run
|
|
|
|
+ /// # use dioxus_lib::prelude::*;
|
|
|
|
+ /// # use dioxus_fullstack::prelude::*;
|
|
|
|
+ /// #[tokio::main]
|
|
|
|
+ /// async fn main() {
|
|
|
|
+ /// let router = axum::Router::new()
|
|
|
|
+ /// .serve_api_application(ServeConfig::new().unwrap(), app)
|
|
|
|
+ /// .into_make_service();
|
|
|
|
+ /// // ...
|
|
|
|
+ /// }
|
|
|
|
+ fn serve_api_application(self, cfg: ServeConfig, app: fn() -> Element) -> Self
|
|
|
|
+ where
|
|
|
|
+ Self: Sized;
|
|
}
|
|
}
|
|
|
|
|
|
impl<S> DioxusRouterFnExt<S> for Router<S>
|
|
impl<S> DioxusRouterFnExt<S> for Router<S>
|
|
@@ -192,6 +213,20 @@ where
|
|
}
|
|
}
|
|
self
|
|
self
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ fn serve_api_application(self, cfg: ServeConfig, app: fn() -> Element) -> Self
|
|
|
|
+ where
|
|
|
|
+ Self: Sized,
|
|
|
|
+ {
|
|
|
|
+ let server = self.register_server_functions_with_context(cfg.context_providers.clone());
|
|
|
|
+
|
|
|
|
+ let ssr_state = SSRState::new(&cfg);
|
|
|
|
+
|
|
|
|
+ server.fallback(
|
|
|
|
+ get(render_handler)
|
|
|
|
+ .with_state(RenderHandleState::new(cfg, app).with_ssr_state(ssr_state)),
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
pub fn register_server_fn_on_router<S>(
|
|
pub fn register_server_fn_on_router<S>(
|