Fix fullstack axum integration docs (#3263)
* Fix broken fullstack doc tests * include all features in doc test * fix clippy
This commit is contained in:
1 parent
354c4ce9cc
commit
9dc567255a
8 files changed
+51
-116
No files matched your search
@@ -40,16 +40,10 @@ impl ServeConfigBuilder {
|
||||
/// # fn app() -> Element { todo!() }
|
||||
/// use dioxus::prelude::*;
|
||||
///
|
||||
/// let mut cfg = dioxus::fullstack::Config::new();
|
||||
///
|
||||
/// // Only set the server config if the server feature is enabled
|
||||
/// server_only! {
|
||||
/// cfg = cfg.with_server_cfg(ServeConfigBuilder::default().incremental(IncrementalRendererConfig::default()));
|
||||
/// }
|
||||
///
|
||||
/// // Finally, launch the app with the config
|
||||
/// LaunchBuilder::new()
|
||||
/// .with_cfg(cfg)
|
||||
/// // Only set the server config if the server feature is enabled
|
||||
/// .with_cfg(server_only!(ServeConfigBuilder::default().incremental(IncrementalRendererConfig::default())))
|
||||
/// .launch(app);
|
||||
/// ```
|
||||
pub fn incremental(mut self, cfg: dioxus_isrg::IncrementalRendererConfig) -> Self {
|
||||
@@ -92,26 +86,20 @@ impl ServeConfigBuilder {
|
||||
/// # fn app() -> Element { todo!() }
|
||||
/// use dioxus::prelude::*;
|
||||
///
|
||||
/// let mut cfg = dioxus::fullstack::Config::new();
|
||||
///
|
||||
/// // Only set the server config if the server feature is enabled
|
||||
/// server_only! {
|
||||
/// cfg = cfg.with_server_cfg(ServeConfigBuilder::default().root_id("app"));
|
||||
/// }
|
||||
///
|
||||
/// // You also need to set the root id in your web config
|
||||
/// web! {
|
||||
/// cfg = cfg.with_web_config(dioxus::web::Config::default().rootname("app"));
|
||||
/// }
|
||||
///
|
||||
/// // And desktop config
|
||||
/// desktop! {
|
||||
/// cfg = cfg.with_desktop_config(dioxus::desktop::Config::default().with_root_name("app"));
|
||||
/// }
|
||||
///
|
||||
/// // Finally, launch the app with the config
|
||||
/// LaunchBuilder::new()
|
||||
/// .with_cfg(cfg)
|
||||
/// // Only set the server config if the server feature is enabled
|
||||
/// .with_cfg(server_only! {
|
||||
/// ServeConfigBuilder::default().root_id("app")
|
||||
/// })
|
||||
/// // You also need to set the root id in your web config
|
||||
/// .with_cfg(web! {
|
||||
/// dioxus::web::Config::default().rootname("app")
|
||||
/// })
|
||||
/// // And desktop config
|
||||
/// .with_cfg(desktop! {
|
||||
/// dioxus::desktop::Config::default().with_root_name("app")
|
||||
/// })
|
||||
/// .launch(app);
|
||||
/// ```
|
||||
pub fn root_id(mut self, root_id: &'static str) -> Self {
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
//! tokio::runtime::Runtime::new()
|
||||
//! .unwrap()
|
||||
//! .block_on(async move {
|
||||
//! let listener = tokio::net::TcpListener::bind("127.0.0.01:8080")
|
||||
//! // Get the address the server should run on. If the CLI is running, the CLI proxies fullstack into the main address
|
||||
//! // and we use the generated address the CLI gives us
|
||||
//! let address = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
//! let listener = tokio::net::TcpListener::bind(address)
|
||||
//! .await
|
||||
//! .unwrap();
|
||||
//! axum::serve(
|
||||
@@ -82,7 +85,7 @@ pub trait DioxusRouterExt<S> {
|
||||
/// # use dioxus_fullstack::prelude::*;
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
/// let addr = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
/// let router = axum::Router::new()
|
||||
/// // Register server functions routes with the default handler
|
||||
/// .register_server_functions()
|
||||
@@ -107,7 +110,7 @@ pub trait DioxusRouterExt<S> {
|
||||
/// # use std::sync::Arc;
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
/// let addr = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
/// let router = axum::Router::new()
|
||||
/// // Register server functions routes with the default handler
|
||||
/// .register_server_functions_with_context(Arc::new(vec![Box::new(|| Box::new(1234567890u32))]))
|
||||
@@ -127,7 +130,7 @@ pub trait DioxusRouterExt<S> {
|
||||
/// # use dioxus_fullstack::prelude::*;
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
/// let addr = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
/// let router = axum::Router::new()
|
||||
/// // Server side render the application, serve static assets, and register server functions
|
||||
/// .serve_static_assets()
|
||||
@@ -152,7 +155,7 @@ pub trait DioxusRouterExt<S> {
|
||||
/// # use dioxus_fullstack::prelude::*;
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
/// let addr = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
/// let router = axum::Router::new()
|
||||
/// // Server side render the application, serve static assets, and register server functions
|
||||
/// .serve_dioxus_application(ServeConfig::new().unwrap(), app)
|
||||
@@ -358,7 +361,7 @@ impl RenderHandleState {
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
/// let addr = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
/// let router = axum::Router::new()
|
||||
/// // Register server functions, etc.
|
||||
/// // Note you can use `register_server_functions_with_context`
|
||||
|
||||
@@ -161,10 +161,11 @@ mod server_fn_impl {
|
||||
/// #[server]
|
||||
/// async fn set_headers() -> Result<(), ServerFnError> {
|
||||
/// let server_context = server_context();
|
||||
/// let cookies = server_context.response_parts()
|
||||
/// .headers()
|
||||
/// let response_parts = server_context.response_parts();
|
||||
/// let cookies = response_parts
|
||||
/// .headers
|
||||
/// .get("Cookie")
|
||||
/// .ok_or_else(|| ServerFnError::msg("failed to find Cookie header in the response"))?;
|
||||
/// .ok_or_else(|| ServerFnError::new("failed to find Cookie header in the response"))?;
|
||||
/// println!("{:?}", cookies);
|
||||
/// Ok(())
|
||||
/// }
|
||||
@@ -185,8 +186,8 @@ mod server_fn_impl {
|
||||
/// async fn set_headers() -> Result<(), ServerFnError> {
|
||||
/// let server_context = server_context();
|
||||
/// server_context.response_parts_mut()
|
||||
/// .headers_mut()
|
||||
/// .insert("Cookie", "dioxus=fullstack");
|
||||
/// .headers
|
||||
/// .insert("Cookie", http::HeaderValue::from_static("dioxus=fullstack"));
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
@@ -205,10 +206,11 @@ mod server_fn_impl {
|
||||
/// #[server]
|
||||
/// async fn read_headers() -> Result<(), ServerFnError> {
|
||||
/// let server_context = server_context();
|
||||
/// let id: &i32 = server_context.request_parts()
|
||||
/// let request_parts = server_context.request_parts();
|
||||
/// let id: &i32 = request_parts
|
||||
/// .extensions
|
||||
/// .get()
|
||||
/// .ok_or_else(|| ServerFnError::msg("failed to find i32 extension in the request"))?;
|
||||
/// .ok_or_else(|| ServerFnError::new("failed to find i32 extension in the request"))?;
|
||||
/// println!("{:?}", id);
|
||||
/// Ok(())
|
||||
/// }
|
||||
@@ -231,7 +233,7 @@ mod server_fn_impl {
|
||||
/// let id: i32 = server_context.request_parts_mut()
|
||||
/// .extensions
|
||||
/// .remove()
|
||||
/// .ok_or_else(|| ServerFnError::msg("failed to find i32 extension in the request"))?;
|
||||
/// .ok_or_else(|| ServerFnError::new("failed to find i32 extension in the request"))?;
|
||||
/// println!("{:?}", id);
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
||||
Reference in new issue
Block a user