Make it easier to provide context to fullstack (#2515)

* pass context providers into server functions

* add an example for FromContext

* clean up DioxusRouterExt

* fix server function context

* fix fullstack desktop example

* fix axum auth example

* fix fullstack context type

* fix context providers path
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-06-18 20:38:06 -05:00
1 parent 7ee3dc41fc
commit b0caf442ab
12 files changed
+152 -64

No files matched your search

+6 -2
View File
@@ -116,9 +116,12 @@ impl Config {
pub async fn launch_server(
self,
build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static,
context_providers: crate::launch::ContextProviders,
) {
use std::any::Any;
let addr = self.addr;
println!("Listening on {}", addr);
println!("Listening on http://{}", addr);
let cfg = self.server_cfg.build();
let server_fn_route = self.server_fn_route;
@@ -129,7 +132,8 @@ impl Config {
use tower::ServiceBuilder;
let ssr_state = SSRState::new(&cfg);
let router = axum::Router::new().register_server_fns();
let router =
axum::Router::new().register_server_functions_with_context(context_providers);
#[cfg(not(any(feature = "desktop", feature = "mobile")))]
let router = {
let mut router = router.serve_static_assets(cfg.assets_path.clone()).await;