Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dioxus = { {{ dioxus_dep_src }} }
# workspace
ui = { path = "ui" }
{% if is_fullstack -%}
server = { path = "server" }
api = { path = "api" }
{%- endif %}
8 changes: 4 additions & 4 deletions Workspace/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development

{% if is_fullstack -%}Your new workspace contains a member crate for each of the web, desktop and mobile platforms, a `ui` crate for shared components and a `server` crate for shared backend logic:{%- else -%}
{% if is_fullstack -%}Your new workspace contains a member crate for each of the web, desktop and mobile platforms, a `ui` crate for shared components and a `api` crate for shared backend logic:{%- else -%}
Your new workspace contains a member crate for each of the web, desktop and mobile platforms, and a `ui` crate for components that are shared between multiple platforms:{%- endif %}

```
Expand All @@ -11,7 +11,7 @@ your_project/
│ ├─ ... # Desktop specific UI/logic
├─ mobile/
│ ├─ ... # Mobile specific UI/logic{% if is_fullstack %}
├─ server/
├─ api/
│ ├─ ... # All shared server logic{% endif %}
├─ ui/
│ ├─ ... # Component shared between multiple platforms
Expand Down Expand Up @@ -51,10 +51,10 @@ ui/
{% if is_fullstack -%}
## Shared backend logic

The workspace contains a `server` crate with shared backend logic. This crate defines all of the shared server functions for all platforms. Server functions are async functions that expose a public API on the server. They can be called like a normal async function from the client. When you run `dx serve`, all of the server functions will be collected in the server build and hosted on a public API for the client to call. The `server` crate starts out something like this:
The workspace contains a `api` crate with shared backend logic. This crate defines all of the shared server functions for all platforms. Server functions are async functions that expose a public API on the server. They can be called like a normal async function from the client. When you run `dx serve`, all of the server functions will be collected in the server build and hosted on a public API for the client to call. The `api` crate starts out something like this:

```
server/
api/
├─ src/
│ ├─ lib.rs # Exports a server function that echos the input string
```
Expand Down
2 changes: 1 addition & 1 deletion Workspace/server/Cargo.toml → Workspace/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "server"
name = "api"
version = "0.1.0"
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions Workspace/server/README.md → Workspace/api/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Server
# API

This crate contains all shared fullstack server functions. This is a great place to place any server-only logic you would like to expose in multiple platforms like a method that accesses your database or a method that sends an email.

This crate will be built twice:
1. Once for the server build with the `server` feature enabled
2. Once for the client build with the `server` feature disabled
1. Once for the server build with the `dioxus/server` feature enabled
2. Once for the client build with the client feature disabled

During the server build, the server functions will be collected and hosted on a public API for the client to call. During the client build, the server functions will be compiled into the client build.

Expand Down
2 changes: 1 addition & 1 deletion Workspace/server/src/lib.rs → Workspace/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ use dioxus::prelude::*;
#[server(Echo)]
pub async fn echo(input: String) -> Result<String, ServerFnError> {
Ok(input)
}
}
2 changes: 1 addition & 1 deletion Workspace/conditional-files.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const IS_ROUTER_VAR = "is_router";

let is_fullstack = variable::get(IS_FULLSTACK_VAR);
if !is_fullstack {
file::delete("server");
file::delete("api");
file::delete("ui/src/echo.rs");
file::delete("ui/assets/styling/echo.css");
}
Expand Down
2 changes: 1 addition & 1 deletion Workspace/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
[dependencies]
dioxus = { workspace = true }
{% if is_fullstack -%}
server = { workspace = true }
api = { workspace = true }
{%- endif %}
2 changes: 1 addition & 1 deletion Workspace/ui/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn Echo() -> Element {
input {
placeholder: "Type here to echo...",
oninput: move |event| async move {
let data = server::echo(event.value()).await.unwrap();
let data = api::echo(event.value()).await.unwrap();
response.set(data);
},
}
Expand Down
2 changes: 1 addition & 1 deletion Workspace/vars.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const IS_ROUTER = "is_router";
let workspace_members = ["web", "desktop", "mobile"];

if variable::get(IS_FULLSTACK) {
workspace_members += "server"
workspace_members += "api"
}

variable::set(WORKSPACE_MEMBERS_VAR, workspace_members);
Expand Down