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