Add liveview support to the CLI and make fullstack runnable from dist (#2759)

* add liveview cli support
* Fix TUI fullstack deadlock
* look for fullstack assets in the public directory
* Fix fullstack with the CLI
* Fix static generation server
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-08-01 17:46:35 -07:00
1 parent 9dbdf74a1e
commit e5e578d27b
14 files changed
+428 -272

No files matched your search

+14 -19
View File
@@ -11,7 +11,6 @@ pub struct ServeConfigBuilder {
pub(crate) root_id: Option<&'static str>,
pub(crate) index_html: Option<String>,
pub(crate) index_path: Option<PathBuf>,
pub(crate) assets_path: Option<PathBuf>,
pub(crate) incremental: Option<dioxus_ssr::incremental::IncrementalRendererConfig>,
}
@@ -22,7 +21,6 @@ impl ServeConfigBuilder {
root_id: None,
index_html: None,
index_path: None,
assets_path: None,
incremental: None,
}
}
@@ -51,25 +49,15 @@ impl ServeConfigBuilder {
self
}
/// Set the path of the assets folder generated by the Dioxus CLI. (defaults to dist)
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(
dioxus_cli_config::CURRENT_CONFIG
.as_ref()
.map(|c| c.application.out_dir.clone())
.unwrap_or("dist".into()),
);
// The CLI always bundles static assets into the exe/public directory
let public_path = public_path();
let index_path = self
.index_path
.map(PathBuf::from)
.unwrap_or_else(|| assets_path.join("index.html"));
.unwrap_or_else(|| public_path.join("index.html"));
let root_id = self.root_id.unwrap_or("main");
@@ -81,14 +69,23 @@ impl ServeConfigBuilder {
ServeConfig {
index,
assets_path,
incremental: self.incremental,
}
}
}
/// Get the path to the public assets directory to serve static files from
pub(crate) fn public_path() -> PathBuf {
// The CLI always bundles static assets into the exe/public directory
std::env::current_exe()
.expect("Failed to get current executable path")
.parent()
.unwrap()
.join("public")
}
fn load_index_path(path: PathBuf) -> String {
let mut file = File::open(path).expect("Failed to find index.html. Make sure the index_path is set correctly and the WASM application has been built.");
let mut file = File::open(&path).unwrap_or_else(|_| panic!("Failed to find index.html. Make sure the index_path is set correctly and the WASM application has been built. Tried to open file at path: {path:?}"));
let mut contents = String::new();
file.read_to_string(&mut contents)
@@ -156,8 +153,6 @@ pub(crate) struct IndexHtml {
#[derive(Clone)]
pub struct ServeConfig {
pub(crate) index: IndexHtml,
#[allow(unused)]
pub(crate) assets_path: PathBuf,
pub(crate) incremental: Option<dioxus_ssr::incremental::IncrementalRendererConfig>,
}