Kaynağa Gözat

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

Evan Almloff 1 yıl önce
ebeveyn
işleme
8eda785ace

+ 1 - 0
Cargo.lock

@@ -2577,6 +2577,7 @@ dependencies = [
  "base64 0.21.7",
  "bytes",
  "ciborium",
+ "dioxus-cli-config",
  "dioxus-desktop",
  "dioxus-hot-reload",
  "dioxus-lib",

+ 3 - 1
packages/fullstack/Cargo.toml

@@ -64,6 +64,8 @@ tower = { version = "0.4.13", features = ["util"], 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"] }
 
+dioxus-cli-config = { workspace = true, optional = true }
+
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 dioxus-hot-reload = { workspace = true }
 
@@ -77,6 +79,6 @@ mobile = ["dioxus-mobile"]
 warp = ["dep:warp", "ssr"]
 axum = ["dep:axum", "tower-http", "ssr"]
 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"]
 rustls = ["server_fn/rustls"]

+ 1 - 1
packages/fullstack/src/adapters/axum_adapter.rs

@@ -325,7 +325,7 @@ where
         let ssr_state = SSRState::new(&cfg);
 
         // 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()
             .register_server_fns(server_fn_route)
             .fallback(get(render_handler).with_state((cfg, Arc::new(build_virtual_dom), ssr_state)))

+ 1 - 1
packages/fullstack/src/config.rs

@@ -123,7 +123,7 @@ impl Config {
             let router = axum::Router::new().register_server_fns(server_fn_route);
             #[cfg(not(any(feature = "desktop", feature = "mobile")))]
             let router = router
-                .serve_static_assets(cfg.assets_path)
+                .serve_static_assets(cfg.assets_path.clone())
                 .connect_hot_reload()
                 .fallback(get(render_handler).with_state((
                     cfg,

+ 12 - 7
packages/fullstack/src/serve_config.rs

@@ -13,8 +13,8 @@ use dioxus_lib::prelude::*;
 #[derive(Clone)]
 pub struct ServeConfigBuilder {
     pub(crate) root_id: Option<&'static str>,
-    pub(crate) index_path: Option<&'static str>,
-    pub(crate) assets_path: Option<&'static str>,
+    pub(crate) index_path: Option<PathBuf>,
+    pub(crate) assets_path: Option<PathBuf>,
     pub(crate) incremental:
         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)
-    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
     }
@@ -69,19 +69,24 @@ impl ServeConfigBuilder {
     }
 
     /// 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
     }
 
     /// Build the 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
             .index_path
             .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");
 
@@ -130,7 +135,7 @@ pub(crate) struct IndexHtml {
 #[derive(Clone)]
 pub struct ServeConfig {
     pub(crate) index: IndexHtml,
-    pub(crate) assets_path: &'static str,
+    pub(crate) assets_path: PathBuf,
     pub(crate) incremental:
         Option<std::sync::Arc<dioxus_ssr::incremental::IncrementalRendererConfig>>,
 }

+ 1 - 0
packages/web/src/rehydrate.rs

@@ -25,6 +25,7 @@ impl WebsysDom {
 
         dioxus_interpreter_js::hydrate(ids);
 
+        #[cfg(feature = "mounted")]
         for id in to_mount {
             self.send_mount_event(id);
         }