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

@@ -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
View File
@@ -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
View File
@@ -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>>,
}