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

+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>>,
}