From 29af6d348ea20cc4ed382240049dc15d0d318d44 Mon Sep 17 00:00:00 2001 From: Joern Barthel Date: Wed, 5 Feb 2025 09:22:47 +0100 Subject: [PATCH 1/2] Added server feature to server crate for fullstack --- Workspace/README.md | 3 ++- Workspace/server/Cargo.toml | 3 +++ Workspace/server/src/lib.rs | 5 +++++ Workspace/web/Cargo.toml | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Workspace/README.md b/Workspace/README.md index 5bec655..b8da8a1 100644 --- a/Workspace/README.md +++ b/Workspace/README.md @@ -2,7 +2,8 @@ Depending on your selected options, your new workspace project contains a workspace member for each platform. If you chose to develop with the router feature, each platform crate will have a `views` folder for your platform-specific views. -You are provided with a `ui` crate for shared UI and if you chose to use fullstack, you will have a `server` crate for your shared server functions. +You are provided with a `ui` crate for shared UI and if you chose to use fullstack, you will have a `server` crate for your shared server functions. +Code gated with the `server` feature in the `server` crate will only be available on the actual server side and can be used e.g. for `axum` integration such as authentication middleware. This distinction is required because the declaration of [server functions](https://crates.io/crates/server_fn) also declares their respective clients. ### Serving Your App diff --git a/Workspace/server/Cargo.toml b/Workspace/server/Cargo.toml index 491fb6b..2f7ff88 100644 --- a/Workspace/server/Cargo.toml +++ b/Workspace/server/Cargo.toml @@ -5,3 +5,6 @@ edition = "2021" [dependencies] dioxus = { workspace = true, features = ["fullstack"] } + +[features] +server = [] \ No newline at end of file diff --git a/Workspace/server/src/lib.rs b/Workspace/server/src/lib.rs index 3962b16..4dccf48 100644 --- a/Workspace/server/src/lib.rs +++ b/Workspace/server/src/lib.rs @@ -1,6 +1,11 @@ //! This crate contains all shared fullstack server functions. use dioxus::prelude::*; +#[cfg(feature = "server")] +pub mod server { + use super::*; +} + /// Echo the user input on the server. #[server(Echo)] pub async fn echo(input: String) -> Result { diff --git a/Workspace/web/Cargo.toml b/Workspace/web/Cargo.toml index 221baa9..94f4ed2 100644 --- a/Workspace/web/Cargo.toml +++ b/Workspace/web/Cargo.toml @@ -11,5 +11,5 @@ ui = { workspace = true } default = [{% if is_fullstack == false -%}"web"{%- endif %}] web = ["dioxus/web"] {% if is_fullstack -%} -server = ["dioxus/server"] +server = ["dioxus/server", "server/server"] {%- endif %} From 63f4868b4a61f583809adc2d3e10aadcb2200d69 Mon Sep 17 00:00:00 2001 From: Joern Barthel Date: Wed, 5 Feb 2025 09:24:10 +0100 Subject: [PATCH 2/2] Added linebreaks --- Workspace/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Workspace/README.md b/Workspace/README.md index b8da8a1..fa31f25 100644 --- a/Workspace/README.md +++ b/Workspace/README.md @@ -1,8 +1,11 @@ # Development Depending on your selected options, your new workspace project contains a workspace member for each platform. + If you chose to develop with the router feature, each platform crate will have a `views` folder for your platform-specific views. + You are provided with a `ui` crate for shared UI and if you chose to use fullstack, you will have a `server` crate for your shared server functions. + Code gated with the `server` feature in the `server` crate will only be available on the actual server side and can be used e.g. for `axum` integration such as authentication middleware. This distinction is required because the declaration of [server functions](https://crates.io/crates/server_fn) also declares their respective clients. ### Serving Your App