Enable serve_dioxus_application for WASM targets (#4170)
* optional asset serving * optional asset serving * Add serve_api_application for WASM environments * fix cfg * remove old placeholder
This commit is contained in:
1 parent
929cab9ecf
commit
eb15b42ab1
1 file changed
+35
@@ -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>(
|
||||||
|
|||||||
Reference in new issue
Block a user