try to pull the default out directory for the fullstack server from the config

This commit is contained in:
Evan Almloff committed 2024-01-31 16:50:54 -06:00
1 parent 13b6f3b9e7
commit 8eda785ace
6 files changed
+19 -10

No files matched your search

Generated
+1
View File
@@ -2577,6 +2577,7 @@ dependencies = [
"base64 0.21.7", "base64 0.21.7",
"bytes", "bytes",
"ciborium", "ciborium",
"dioxus-cli-config",
"dioxus-desktop", "dioxus-desktop",
"dioxus-hot-reload", "dioxus-hot-reload",
"dioxus-lib", "dioxus-lib",
+3 -1
View File
@@ -64,6 +64,8 @@ tower = { version = "0.4.13", features = ["util"], optional = true }
tower-layer = { version = "0.3.2", optional = true } tower-layer = { version = "0.3.2", optional = true }
web-sys = { version = "0.3.61", optional = true, features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] } web-sys = { version = "0.3.61", optional = true, features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
dioxus-cli-config = { workspace = true, optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
dioxus-hot-reload = { workspace = true } dioxus-hot-reload = { workspace = true }
@@ -77,6 +79,6 @@ mobile = ["dioxus-mobile"]
warp = ["dep:warp", "ssr"] warp = ["dep:warp", "ssr"]
axum = ["dep:axum", "tower-http", "ssr"] axum = ["dep:axum", "tower-http", "ssr"]
salvo = ["dep:salvo", "ssr", "http-body-util"] salvo = ["dep:salvo", "ssr", "http-body-util"]
ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "tokio-stream", "dioxus-ssr", "dioxus-ssr/incremental", "tower", "hyper", "http", "tower-layer", "anymap", "tracing-futures", "pin-project", "thiserror"] ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "tokio-stream", "dioxus-ssr", "dioxus-ssr/incremental", "tower", "hyper", "http", "tower-layer", "anymap", "tracing-futures", "pin-project", "thiserror", "dioxus-cli-config"]
default-tls = ["server_fn/default-tls"] default-tls = ["server_fn/default-tls"]
rustls = ["server_fn/rustls"] rustls = ["server_fn/rustls"]
@@ -325,7 +325,7 @@ where
let ssr_state = SSRState::new(&cfg); let ssr_state = SSRState::new(&cfg);
// Add server functions and render index.html // Add server functions and render index.html
self.serve_static_assets(cfg.assets_path) self.serve_static_assets(cfg.assets_path.clone())
.connect_hot_reload() .connect_hot_reload()
.register_server_fns(server_fn_route) .register_server_fns(server_fn_route)
.fallback(get(render_handler).with_state((cfg, Arc::new(build_virtual_dom), ssr_state))) .fallback(get(render_handler).with_state((cfg, Arc::new(build_virtual_dom), ssr_state)))
+1 -1
View File
@@ -123,7 +123,7 @@ impl Config {
let router = axum::Router::new().register_server_fns(server_fn_route); let router = axum::Router::new().register_server_fns(server_fn_route);
#[cfg(not(any(feature = "desktop", feature = "mobile")))] #[cfg(not(any(feature = "desktop", feature = "mobile")))]
let router = router let router = router
.serve_static_assets(cfg.assets_path) .serve_static_assets(cfg.assets_path.clone())
.connect_hot_reload() .connect_hot_reload()
.fallback(get(render_handler).with_state(( .fallback(get(render_handler).with_state((
cfg, cfg,
+12 -7
View File
@@ -13,8 +13,8 @@ use dioxus_lib::prelude::*;
#[derive(Clone)] #[derive(Clone)]
pub struct ServeConfigBuilder { pub struct ServeConfigBuilder {
pub(crate) root_id: Option<&'static str>, pub(crate) root_id: Option<&'static str>,
pub(crate) index_path: Option<&'static str>, pub(crate) index_path: Option<PathBuf>,
pub(crate) assets_path: Option<&'static str>, pub(crate) assets_path: Option<PathBuf>,
pub(crate) incremental: pub(crate) incremental:
Option<std::sync::Arc<dioxus_ssr::incremental::IncrementalRendererConfig>>, Option<std::sync::Arc<dioxus_ssr::incremental::IncrementalRendererConfig>>,
} }
@@ -57,7 +57,7 @@ impl ServeConfigBuilder {
} }
/// Set the path of the index.html file to be served. (defaults to {assets_path}/index.html) /// Set the path of the index.html file to be served. (defaults to {assets_path}/index.html)
pub fn index_path(mut self, index_path: &'static str) -> Self { pub fn index_path(mut self, index_path: PathBuf) -> Self {
self.index_path = Some(index_path); self.index_path = Some(index_path);
self self
} }
@@ -69,19 +69,24 @@ impl ServeConfigBuilder {
} }
/// Set the path of the assets folder generated by the Dioxus CLI. (defaults to dist) /// Set the path of the assets folder generated by the Dioxus CLI. (defaults to dist)
pub fn assets_path(mut self, assets_path: &'static str) -> Self { pub fn assets_path(mut self, assets_path: PathBuf) -> Self {
self.assets_path = Some(assets_path); self.assets_path = Some(assets_path);
self self
} }
/// Build the ServeConfig /// Build the ServeConfig
pub fn build(self) -> ServeConfig { pub fn build(self) -> ServeConfig {
let assets_path = self.assets_path.unwrap_or("dist"); let assets_path = self.assets_path.unwrap_or(
dioxus_cli_config::CURRENT_CONFIG
.as_ref()
.map(|c| c.dioxus_config.application.out_dir.clone())
.unwrap_or("dist".into()),
);
let index_path = self let index_path = self
.index_path .index_path
.map(PathBuf::from) .map(PathBuf::from)
.unwrap_or_else(|| format!("{assets_path}/index.html").into()); .unwrap_or_else(|| assets_path.join("index.html"));
let root_id = self.root_id.unwrap_or("main"); let root_id = self.root_id.unwrap_or("main");
@@ -130,7 +135,7 @@ pub(crate) struct IndexHtml {
#[derive(Clone)] #[derive(Clone)]
pub struct ServeConfig { pub struct ServeConfig {
pub(crate) index: IndexHtml, pub(crate) index: IndexHtml,
pub(crate) assets_path: &'static str, pub(crate) assets_path: PathBuf,
pub(crate) incremental: pub(crate) incremental:
Option<std::sync::Arc<dioxus_ssr::incremental::IncrementalRendererConfig>>, Option<std::sync::Arc<dioxus_ssr::incremental::IncrementalRendererConfig>>,
} }
+1
View File
@@ -25,6 +25,7 @@ impl WebsysDom {
dioxus_interpreter_js::hydrate(ids); dioxus_interpreter_js::hydrate(ids);
#[cfg(feature = "mounted")]
for id in to_mount { for id in to_mount {
self.send_mount_event(id); self.send_mount_event(id);
} }