provide a nicer builder API

This commit is contained in:
Evan Almloff committed 2023-04-01 17:00:09 -05:00
1 parent 5ffdb4dbed
commit 71ddd50963
6 files changed
+64 -43

No files matched your search

@@ -23,11 +23,7 @@ fn main() {
axum::Server::bind(&addr)
.serve(
axum::Router::new()
.serve_dioxus_application(
ServeConfig::new(app, ()).head(r#"<title>Hello World!</title>"#),
None,
)
.with_state(SSRState::default())
.serve_dioxus_application("", ServeConfigBuilder::new(app, ()))
.into_make_service(),
)
.await
@@ -41,12 +41,15 @@ fn main() {
// If the path is unknown, render the application
.fallback(
move |uri: http::uri::Uri, State(ssr_state): State<SSRState>| {
let rendered = ssr_state.render(&ServeConfig::new(
App,
AppProps {
route: Some(format!("http://{addr}{uri}")),
},
));
let rendered = ssr_state.render(
&ServeConfigBuilder::new(
App,
AppProps {
route: Some(format!("http://{addr}{uri}")),
},
)
.build(),
);
async move { axum::body::Full::from(rendered) }
},
)
@@ -79,7 +82,7 @@ fn App(cx: Scope<AppProps>) -> Element {
for _ in 0..100 {
tr {
for _ in 0..100 {
td { "hello world??" }
td { "hello world!" }
}
}
}
@@ -20,9 +20,8 @@ fn main() {
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
let router = Router::new().serve_dioxus_application(
ServeConfig::new(app, ()).head(r#"<title>Hello World!</title>"#),
);
let router =
Router::new().serve_dioxus_application("", ServeConfigBuilder::new(app, ()));
Server::new(TcpListener::bind("127.0.0.1:8080"))
.serve(router)
.await;
@@ -19,9 +19,7 @@ fn main() {
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
let routes = serve_dioxus_application(
ServeConfig::new(app, ()).head(r#"<title>Hello World!</title>"#),
);
let routes = serve_dioxus_application("", ServeConfigBuilder::new(app, ()));
warp::serve(routes).run(([127, 0, 0, 1], 8080)).await;
});
}