2023-04-03 13:09:22 +00:00
//! Fullstack utilities for the [`dioxus`](https://dioxuslabs.com) framework.
//!
//! # Features
//! - Intigrations with the [axum](crate::adapters::axum_adapter), [salvo](crate::adapters::salvo_adapters), and [warp](crate::adapters::warp_adapters) server frameworks with utilities for serving and rendering Dioxus applications.
//! - Server functions that allow you to call code on the server from the client as if it were a normal function.
//! - Instant RSX Hot reloading with [`dioxus-hot-reload`](https://crates.io/crates/dioxus-hot-reload).
//!
//! # Example
2023-04-03 17:45:01 +00:00
//! Full stack Dioxus in under 50 lines of code
2023-04-03 13:09:22 +00:00
//! ```rust
//! #![allow(non_snake_case)]
//! use dioxus::prelude::*;
//! use dioxus_server::prelude::*;
//!
//! fn main() {
//! #[cfg(feature = "web")]
//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
//! #[cfg(feature = "ssr")]
//! {
2023-04-03 17:45:01 +00:00
//! GetMeaning::register().unwrap();
2023-04-03 13:09:22 +00:00
//! tokio::runtime::Runtime::new()
//! .unwrap()
//! .block_on(async move {
2023-04-03 17:45:01 +00:00
//! warp::serve(serve_dioxus_application(
//! "",
//! ServeConfigBuilder::new(app, ()),
//! ))
//! .run(([127, 0, 0, 1], 8080))
//! .await;
2023-04-03 13:09:22 +00:00
//! });
2023-04-03 17:45:01 +00:00
//! }
2023-04-03 13:09:22 +00:00
//! }
//!
//! fn app(cx: Scope) -> Element {
2023-04-03 17:45:01 +00:00
//! let meaning = use_state(cx, || None);
2023-04-03 13:09:22 +00:00
//! cx.render(rsx! {
//! button {
//! onclick: move |_| {
2023-04-03 17:45:01 +00:00
//! to_owned![meaning];
2023-04-03 13:09:22 +00:00
//! async move {
2023-04-03 17:45:01 +00:00
//! if let Ok(data) = get_meaning("life the universe and everything".into()).await {
//! meaning.set(data);
2023-04-03 13:09:22 +00:00
//! }
//! }
//! },
//! "Run a server function"
//! }
2023-04-03 17:45:01 +00:00
//! "Server said: {meaning:?}"
2023-04-03 13:09:22 +00:00
//! })
//! }
//!
2023-04-03 17:45:01 +00:00
//! // This code will only run on the server
//! #[server(GetMeaning)]
//! async fn get_meaning(of: String) -> Result<Option<u32>, ServerFnError> {
//! Ok(of.contains("life").then(|| 42))
2023-04-03 13:09:22 +00:00
//! }
//! ```
#![ warn(missing_docs) ]
2023-03-30 15:34:13 +00:00
#[ allow(unused) ]
use dioxus_core ::prelude ::* ;
2023-03-28 18:35:17 +00:00
2023-03-30 15:34:13 +00:00
mod adapters ;
2023-04-02 22:45:28 +00:00
#[ cfg(all(debug_assertions, feature = " hot-reload " , feature = " ssr " )) ]
mod hot_reload ;
2023-03-30 20:58:03 +00:00
#[ cfg(feature = " ssr " ) ]
2023-04-03 13:09:22 +00:00
mod render ;
2023-03-31 20:33:44 +00:00
#[ cfg(feature = " ssr " ) ]
2023-04-03 13:09:22 +00:00
mod serve_config ;
2023-04-01 22:00:12 +00:00
mod server_context ;
2023-03-30 15:34:13 +00:00
mod server_fn ;
2023-04-03 13:09:22 +00:00
/// A prelude of commonly used items in dioxus-server.
2023-03-30 15:34:13 +00:00
pub mod prelude {
#[ cfg(feature = " axum " ) ]
pub use crate ::adapters ::axum_adapter ::* ;
2023-03-31 00:42:46 +00:00
#[ cfg(feature = " salvo " ) ]
pub use crate ::adapters ::salvo_adapter ::* ;
2023-03-31 14:40:58 +00:00
#[ cfg(feature = " warp " ) ]
pub use crate ::adapters ::warp_adapter ::* ;
2023-03-30 20:58:03 +00:00
#[ cfg(feature = " ssr " ) ]
2023-04-03 13:09:22 +00:00
pub use crate ::serve_config ::{ ServeConfig , ServeConfigBuilder } ;
2023-04-01 22:00:12 +00:00
pub use crate ::server_context ::DioxusServerContext ;
pub use crate ::server_fn ::ServerFn ;
#[ cfg(feature = " ssr " ) ]
pub use crate ::server_fn ::ServerFnTraitObj ;
2023-03-30 15:34:13 +00:00
pub use server_fn ::{ self , ServerFn as _ , ServerFnError } ;
pub use server_macro ::* ;
2023-03-28 18:35:17 +00:00
}