diff --git a/packages/server/examples/hello-world/.gitignore b/packages/server/examples/axum-hello-world/.gitignore similarity index 100% rename from packages/server/examples/hello-world/.gitignore rename to packages/server/examples/axum-hello-world/.gitignore diff --git a/packages/server/examples/hello-world/Cargo.toml b/packages/server/examples/axum-hello-world/Cargo.toml similarity index 95% rename from packages/server/examples/hello-world/Cargo.toml rename to packages/server/examples/axum-hello-world/Cargo.toml index 846c03ea4..54aaf17d3 100644 --- a/packages/server/examples/hello-world/Cargo.toml +++ b/packages/server/examples/axum-hello-world/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hello-world" +name = "axum-hello-world" version = "0.1.0" edition = "2021" diff --git a/packages/server/examples/hello-world/src/main.rs b/packages/server/examples/axum-hello-world/src/main.rs similarity index 95% rename from packages/server/examples/hello-world/src/main.rs rename to packages/server/examples/axum-hello-world/src/main.rs index 2fd6b1bde..4d4ab5e78 100644 --- a/packages/server/examples/hello-world/src/main.rs +++ b/packages/server/examples/axum-hello-world/src/main.rs @@ -1,5 +1,5 @@ //! Run with: -//! +//! //! ```sh //! dioxus build --features web //! cargo run --features ssr @@ -24,7 +24,7 @@ fn main() { .serve( axum::Router::new() .serve_dioxus_application( - ServeConfig::new(app).head(r#"
,
+ ) -> Self;
}
-fn transform_rx(message: Result ,
+ ) -> Self {
+ // Serve the dist folder and the index.html file
+ let serve_dir = StaticDir::new(["dist"]);
- Ok(msg)
+ self.register_server_fns(cfg.server_fn_route.unwrap_or_default())
+ .push(Router::with_path("/").get(SSRHandler { cfg }))
+ .push(Router::with_path("<**path>").get(serve_dir))
+ }
}
-async fn transform_tx(message: String) -> Result ,
+}
+
+#[async_trait]
+impl {
+ async fn handle(
+ &self,
+ _req: &mut Request,
+ _depot: &mut Depot,
+ res: &mut Response,
+ _flow: &mut FlowCtrl,
+ ) {
+ res.write_body(dioxus_ssr_html(&self.cfg)).unwrap();
+ }
+}
+
+struct ServerFnHandler {
+ server_context: DioxusServerContext,
+ function: Arc