mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
try to pull the default out directory for the fullstack server from the config
This commit is contained in:
parent
13b6f3b9e7
commit
8eda785ace
6 changed files with 19 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2577,6 +2577,7 @@ dependencies = [
|
|||
"base64 0.21.7",
|
||||
"bytes",
|
||||
"ciborium",
|
||||
"dioxus-cli-config",
|
||||
"dioxus-desktop",
|
||||
"dioxus-hot-reload",
|
||||
"dioxus-lib",
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>>,
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ impl WebsysDom {
|
|||
|
||||
dioxus_interpreter_js::hydrate(ids);
|
||||
|
||||
#[cfg(feature = "mounted")]
|
||||
for id in to_mount {
|
||||
self.send_mount_event(id);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue