mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 14:44:12 +00:00
change config flags from ssr to server to match the features
This commit is contained in:
parent
69e4ebe4ed
commit
b63c14fab8
20 changed files with 80 additions and 80 deletions
|
@ -7,7 +7,7 @@ description = "Fullstack Dioxus Utilities"
|
|||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/DioxusLabs/dioxus/"
|
||||
homepage = "https://dioxuslabs.com"
|
||||
keywords = ["ui", "gui", "react", "ssr", "fullstack"]
|
||||
keywords = ["ui", "gui", "react", "server", "fullstack"]
|
||||
resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -44,7 +44,7 @@ fn main() {
|
|||
get_root_props_from_document().unwrap_or_default(),
|
||||
dioxus_web::Config::new().hydrate(true),
|
||||
);
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#![allow(non_snake_case, unused)]
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod auth;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
@ -19,7 +19,7 @@ fn main() {
|
|||
// Hydrate the application on the client
|
||||
dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
use crate::auth::*;
|
||||
use axum::routing::*;
|
||||
|
|
|
@ -25,4 +25,4 @@ required-features = ["desktop"]
|
|||
[[bin]]
|
||||
name = "server"
|
||||
path = "src/server.rs"
|
||||
required-features = ["ssr"]
|
||||
required-features = ["server"]
|
||||
|
|
|
@ -51,7 +51,7 @@ fn main() {
|
|||
#[cfg(feature = "web")]
|
||||
tracing_wasm::set_as_global_default();
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
launch(app);
|
||||
|
|
|
@ -8,7 +8,7 @@ use dioxus::prelude::*;
|
|||
|
||||
fn main() {
|
||||
let config = LaunchBuilder::fullstack();
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
config
|
||||
.incremental(
|
||||
IncrementalRendererConfig::default()
|
||||
|
@ -16,7 +16,7 @@ fn main() {
|
|||
)
|
||||
.launch();
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
#[cfg(not(feature = "server"))]
|
||||
config.launch(|| {
|
||||
rsx! {
|
||||
Router::<Route> {}
|
||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
#[cfg(feature = "web")]
|
||||
tracing_wasm::set_as_global_default();
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
LaunchBuilder::fullstack().launch(app);
|
||||
|
|
|
@ -11,7 +11,7 @@ use dioxus_fullstack::{launch, prelude::*};
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// Generate all routes and output them to the docs path
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
pre_cache_static_routes_with_props(
|
||||
|
@ -37,7 +37,7 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "web", feature = "ssr")))]
|
||||
#[cfg(not(any(feature = "web", feature = "server")))]
|
||||
fn main() {}
|
||||
|
||||
#[derive(Clone, Routable, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
|
|
@ -47,7 +47,7 @@ async fn get_server_data() -> Result<String, ServerFnError> {
|
|||
fn main() {
|
||||
#[cfg(feature = "web")]
|
||||
tracing_wasm::set_as_global_default();
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
launch(app);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
//! #[cfg(feature = "web")]
|
||||
//! // Hydrate the application on the client
|
||||
//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
|
||||
//! #[cfg(feature = "ssr")]
|
||||
//! #[cfg(feature = "server")]
|
||||
//! {
|
||||
//! tokio::runtime::Runtime::new()
|
||||
//! .unwrap()
|
||||
|
@ -332,7 +332,7 @@ where
|
|||
}
|
||||
|
||||
fn connect_hot_reload(self) -> Self {
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
{
|
||||
self.nest(
|
||||
"/_dioxus",
|
||||
|
@ -354,7 +354,7 @@ where
|
|||
.route("/hot_reload", get(hot_reload_handler)),
|
||||
)
|
||||
}
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))]
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "server")))]
|
||||
{
|
||||
self
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ fn report_err<E: std::fmt::Display>(e: E) -> Response<BoxBody> {
|
|||
}
|
||||
|
||||
/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change.
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
pub async fn hot_reload_handler(ws: axum::extract::WebSocketUpgrade) -> impl IntoResponse {
|
||||
use axum::extract::ws::Message;
|
||||
use futures_util::StreamExt;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//! fn main() {
|
||||
//! #[cfg(feature = "web")]
|
||||
//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
|
||||
//! #[cfg(feature = "ssr")]
|
||||
//! #[cfg(feature = "server")]
|
||||
//! {
|
||||
//! use salvo::prelude::*;
|
||||
//! tokio::runtime::Runtime::new()
|
||||
|
@ -301,7 +301,7 @@ impl DioxusRouterExt for Router {
|
|||
let mut _dioxus_router = Router::with_path("_dioxus");
|
||||
_dioxus_router =
|
||||
_dioxus_router.push(Router::with_path("hot_reload").handle(HotReloadHandler));
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
{
|
||||
_dioxus_router = _dioxus_router.push(Router::with_path("disconnect").handle(ignore_ws));
|
||||
}
|
||||
|
@ -485,11 +485,11 @@ fn handle_error(error: impl Error + Send + Sync, res: &mut Response) {
|
|||
}
|
||||
|
||||
/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change.
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))]
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "server")))]
|
||||
#[derive(Default)]
|
||||
pub struct HotReloadHandler;
|
||||
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))]
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "server")))]
|
||||
#[handler]
|
||||
impl HotReloadHandler {
|
||||
async fn handle(
|
||||
|
@ -503,11 +503,11 @@ impl HotReloadHandler {
|
|||
}
|
||||
|
||||
/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change.
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
#[derive(Default)]
|
||||
pub struct HotReloadHandler;
|
||||
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
#[handler]
|
||||
impl HotReloadHandler {
|
||||
async fn handle(
|
||||
|
@ -561,7 +561,7 @@ impl HotReloadHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
#[handler]
|
||||
async fn ignore_ws(req: &mut Request, res: &mut Response) -> Result<(), salvo::http::StatusError> {
|
||||
use salvo::websocket::WebSocketUpgrade;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//! fn main() {
|
||||
//! #[cfg(feature = "web")]
|
||||
//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true));
|
||||
//! #[cfg(feature = "ssr")]
|
||||
//! #[cfg(feature = "server")]
|
||||
//! {
|
||||
//! tokio::runtime::Runtime::new()
|
||||
//! .unwrap()
|
||||
|
@ -332,13 +332,13 @@ impl warp::reject::Reject for RecieveFailed {}
|
|||
/// ```
|
||||
pub fn connect_hot_reload() -> impl Filter<Extract = (impl Reply,), Error = warp::Rejection> + Clone
|
||||
{
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))]
|
||||
#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "server")))]
|
||||
{
|
||||
warp::path!("_dioxus" / "hot_reload")
|
||||
.map(warp::reply)
|
||||
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND))
|
||||
}
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
{
|
||||
use crate::hot_reload::HotReloadState;
|
||||
use futures_util::sink::SinkExt;
|
||||
|
@ -349,7 +349,7 @@ pub fn connect_hot_reload() -> impl Filter<Extract = (impl Reply,), Error = warp
|
|||
.and(warp::any().then(crate::hot_reload::spawn_hot_reload))
|
||||
.and(warp::ws())
|
||||
.map(move |state: &'static HotReloadState, ws: warp::ws::Ws| {
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
ws.on_upgrade(move |mut websocket| {
|
||||
async move {
|
||||
println!("🔥 Hot Reload WebSocket connected");
|
||||
|
@ -393,7 +393,7 @@ pub fn connect_hot_reload() -> impl Filter<Extract = (impl Reply,), Error = warp
|
|||
.and(warp::ws())
|
||||
.map(move |ws: warp::ws::Ws| {
|
||||
println!("disconnect");
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
ws.on_upgrade(move |mut websocket| async move {
|
||||
struct DisconnectOnDrop(Option<warp::ws::WebSocket>);
|
||||
impl Drop for DisconnectOnDrop {
|
||||
|
|
|
@ -6,13 +6,13 @@ use std::sync::Arc;
|
|||
|
||||
/// Settings for a fullstack app.
|
||||
pub struct Config {
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) server_fn_route: &'static str,
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) server_cfg: ServeConfigBuilder,
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) addr: std::net::SocketAddr,
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
|
@ -29,11 +29,11 @@ pub struct Config {
|
|||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
server_fn_route: "",
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
addr: std::net::SocketAddr::from(([127, 0, 0, 1], 8080)),
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
server_cfg: ServeConfigBuilder::new(),
|
||||
#[cfg(feature = "web")]
|
||||
web_cfg: dioxus_web::Config::default(),
|
||||
|
@ -52,14 +52,14 @@ impl Config {
|
|||
}
|
||||
|
||||
/// Set the address to serve the app on.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub fn addr(self, addr: impl Into<std::net::SocketAddr>) -> Self {
|
||||
let addr = addr.into();
|
||||
Self { addr, ..self }
|
||||
}
|
||||
|
||||
/// Set the route to the server functions.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub fn server_fn_route(self, server_fn_route: &'static str) -> Self {
|
||||
Self {
|
||||
server_fn_route,
|
||||
|
@ -68,7 +68,7 @@ impl Config {
|
|||
}
|
||||
|
||||
/// Set the incremental renderer config.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub fn incremental(self, cfg: IncrementalRendererConfig) -> Self {
|
||||
Self {
|
||||
server_cfg: self.server_cfg.incremental(cfg),
|
||||
|
@ -77,7 +77,7 @@ impl Config {
|
|||
}
|
||||
|
||||
/// Set the server config.
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub fn server_cfg(self, server_cfg: ServeConfigBuilder) -> Self {
|
||||
Self { server_cfg, ..self }
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ impl Config {
|
|||
Self { mobile_cfg, ..self }
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
/// Launch a server application
|
||||
pub async fn launch_server(
|
||||
self,
|
||||
|
|
|
@ -20,7 +20,7 @@ use serde::{de::DeserializeOwned, Serialize};
|
|||
/// }
|
||||
/// ```
|
||||
pub fn server_cached<O: 'static + Serialize + DeserializeOwned>(server_fn: impl Fn() -> O) -> O {
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
let data = server_fn();
|
||||
let sc = crate::prelude::server_context();
|
||||
|
@ -29,7 +29,7 @@ pub fn server_cached<O: 'static + Serialize + DeserializeOwned>(server_fn: impl
|
|||
}
|
||||
data
|
||||
}
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
#[cfg(not(feature = "server"))]
|
||||
{
|
||||
crate::html_storage::deserialize::take_server_data().unwrap_or_else(server_fn)
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ where
|
|||
let out = user_fut.await;
|
||||
|
||||
// If this is the first run and we are on the server, cache the data
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
if currently_in_first_run {
|
||||
let _ = crate::server_context::server_context().push_html_data(&out);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ pub(crate) fn take_server_data<T: DeserializeOwned>() -> Option<T> {
|
|||
SERVER_DATA.as_ref()?.take()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
#[cfg(not(feature = "server"))]
|
||||
/// Get the props from the document. This is only available in the browser.
|
||||
///
|
||||
/// When dioxus-fullstack renders the page, it will serialize the root props and put them in the document. This function gets them from the document.
|
||||
|
|
|
@ -14,7 +14,7 @@ pub(crate) fn serde_to_writable<T: Serialize>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
/// Encode data into a element. This is inteded to be used in the server to send data to the client.
|
||||
pub(crate) fn encode_props_in_element<T: Serialize>(
|
||||
data: &T,
|
||||
|
@ -27,7 +27,7 @@ pub(crate) fn encode_props_in_element<T: Serialize>(
|
|||
Ok(write_to.write_all(r#"" />"#.as_bytes())?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
/// Encode data into a element. This is inteded to be used in the server to send data to the client.
|
||||
pub(crate) fn encode_in_element(
|
||||
data: &super::HTMLData,
|
||||
|
|
|
@ -20,14 +20,14 @@ pub fn launch(
|
|||
vdom
|
||||
};
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
platform_config.launch_server(virtual_dom_factory).await;
|
||||
});
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
#[cfg(not(feature = "server"))]
|
||||
{
|
||||
#[cfg(feature = "web")]
|
||||
{
|
||||
|
|
|
@ -7,23 +7,23 @@ pub use once_cell;
|
|||
|
||||
mod html_storage;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod adapters;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use adapters::*;
|
||||
mod config;
|
||||
mod hooks;
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "server"))]
|
||||
mod hot_reload;
|
||||
pub mod launch;
|
||||
pub use config::*;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod layer;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod render;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod serve_config;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
mod server_context;
|
||||
mod server_fn;
|
||||
|
||||
|
@ -36,29 +36,29 @@ pub mod prelude {
|
|||
#[cfg(feature = "warp")]
|
||||
pub use crate::adapters::warp_adapter::*;
|
||||
use crate::hooks;
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
#[cfg(not(feature = "server"))]
|
||||
pub use crate::html_storage::deserialize::get_root_props_from_document;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::layer::{Layer, Service};
|
||||
#[cfg(all(feature = "ssr", feature = "router"))]
|
||||
#[cfg(all(feature = "server", feature = "router"))]
|
||||
pub use crate::render::pre_cache_static_routes_with_props;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::render::SSRState;
|
||||
#[cfg(feature = "router")]
|
||||
pub use crate::router::FullstackRouterConfig;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::serve_config::{ServeConfig, ServeConfigBuilder};
|
||||
#[cfg(all(feature = "ssr", feature = "axum"))]
|
||||
#[cfg(all(feature = "server", feature = "axum"))]
|
||||
pub use crate::server_context::Axum;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::server_context::{
|
||||
extract, server_context, DioxusServerContext, FromServerContext, ProvideServerContext,
|
||||
};
|
||||
pub use crate::server_fn::DioxusServerFn;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use crate::server_fn::{ServerFnMiddleware, ServerFnTraitObj, ServerFunction};
|
||||
pub use dioxus_server_macro::*;
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub use dioxus_ssr::incremental::IncrementalRendererConfig;
|
||||
pub use server_fn::{self, ServerFn as _, ServerFnError};
|
||||
|
||||
|
@ -66,11 +66,11 @@ pub mod prelude {
|
|||
}
|
||||
|
||||
// Warn users about overlapping features
|
||||
#[cfg(all(feature = "ssr", feature = "web", not(doc)))]
|
||||
#[cfg(all(feature = "server", feature = "web", not(doc)))]
|
||||
compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `web` feature are overlapping. Please choose one or the other.");
|
||||
|
||||
#[cfg(all(feature = "ssr", feature = "desktop", not(doc)))]
|
||||
#[cfg(all(feature = "server", feature = "desktop", not(doc)))]
|
||||
compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `desktop` feature are overlapping. Please choose one or the other.");
|
||||
|
||||
#[cfg(all(feature = "ssr", feature = "mobile", not(doc)))]
|
||||
#[cfg(all(feature = "server", feature = "mobile", not(doc)))]
|
||||
compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `mobile` feature are overlapping. Please choose one or the other.");
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
#[derive(Clone)]
|
||||
/// A trait object for a function that be called on serializable arguments and returns a serializable result.
|
||||
pub struct ServerFnTraitObj(server_fn::ServerFnTraitObj<()>);
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
impl std::ops::Deref for ServerFnTraitObj {
|
||||
type Target = server_fn::ServerFnTraitObj<()>;
|
||||
|
||||
|
@ -12,14 +12,14 @@ impl std::ops::Deref for ServerFnTraitObj {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
impl std::ops::DerefMut for ServerFnTraitObj {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
impl ServerFnTraitObj {
|
||||
fn new(
|
||||
prefix: &'static str,
|
||||
|
@ -36,10 +36,10 @@ impl ServerFnTraitObj {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
server_fn::inventory::collect!(ServerFnTraitObj);
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
/// Middleware for a server function
|
||||
pub struct ServerFnMiddleware {
|
||||
/// The prefix of the server function.
|
||||
|
@ -50,7 +50,7 @@ pub struct ServerFnMiddleware {
|
|||
pub middleware: fn() -> Vec<std::sync::Arc<dyn crate::layer::Layer>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) static MIDDLEWARE: once_cell::sync::Lazy<
|
||||
std::collections::HashMap<
|
||||
(&'static str, &'static str),
|
||||
|
@ -69,14 +69,14 @@ pub(crate) static MIDDLEWARE: once_cell::sync::Lazy<
|
|||
map
|
||||
});
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
server_fn::inventory::collect!(ServerFnMiddleware);
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
/// A server function that can be called on serializable arguments and returns a serializable result.
|
||||
pub type ServerFunction = server_fn::SerializedFnTraitObj<()>;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
#[allow(clippy::type_complexity)]
|
||||
static REGISTERED_SERVER_FUNCTIONS: once_cell::sync::Lazy<
|
||||
std::sync::Arc<std::sync::RwLock<std::collections::HashMap<&'static str, ServerFnTraitObj>>>,
|
||||
|
@ -88,11 +88,11 @@ static REGISTERED_SERVER_FUNCTIONS: once_cell::sync::Lazy<
|
|||
std::sync::Arc::new(std::sync::RwLock::new(map))
|
||||
});
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
/// The registry of all Dioxus server functions.
|
||||
pub struct DioxusServerFnRegistry;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[cfg(feature = "server")]
|
||||
impl server_fn::ServerFunctionRegistry<()> for DioxusServerFnRegistry {
|
||||
type Error = ServerRegistrationFnError;
|
||||
|
||||
|
@ -155,7 +155,7 @@ impl server_fn::ServerFunctionRegistry<()> for DioxusServerFnRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
/// Errors that can occur when registering a server function.
|
||||
#[derive(thiserror::Error, Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ServerRegistrationFnError {
|
||||
|
@ -178,7 +178,7 @@ pub enum ServerRegistrationFnError {
|
|||
/// Technically, the trait is implemented on a type that describes the server function's arguments, not the function itself.
|
||||
pub trait DioxusServerFn: server_fn::ServerFn<()> {
|
||||
/// Registers the server function, allowing the client to query it by URL.
|
||||
#[cfg(any(feature = "ssr", doc))]
|
||||
#[cfg(any(feature = "server", doc))]
|
||||
fn register_explicit() -> Result<(), server_fn::ServerFnError> {
|
||||
Self::register_in_explicit::<DioxusServerFnRegistry>()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue