* issue-5045 Trim slashes to prevent base path resolution issues in web * Revert "issue-5045 Trim slashes to prevent base path resolution issues in web" This reverts commit 480cd48d8537a56f57538c21e7cc98b75e8dc8ad. * This is a more comprehensive approach. No matter how "/" gets set into DIOXUS_ASSET_ROOT (cli arg, dioxus toml, or env var) it will be normalized when used. * Move the trim fix to the locations we set the variable DIOXUS_ASSET_ROOT as this environment variable is not meant for public consumption. * pull out trimming into a method --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
e5a98d094d
commit
3bcb76b21c
2 files changed
+12
-10
No files matched your search
@@ -521,7 +521,7 @@ impl AppBuilder {
|
||||
envs.push(("RUST_BACKTRACE".into(), "1".to_string()));
|
||||
}
|
||||
|
||||
if let Some(base_path) = krate.base_path() {
|
||||
if let Some(base_path) = krate.trimmed_base_path() {
|
||||
envs.push((
|
||||
dioxus_cli_config::ASSET_ROOT_ENV.into(),
|
||||
base_path.to_string(),
|
||||
|
||||
@@ -2801,7 +2801,7 @@ impl BuildRequest {
|
||||
// If this is a release build, bake the base path and title into the binary with env vars.
|
||||
// todo: should we even be doing this? might be better being a build.rs or something else.
|
||||
if self.release {
|
||||
if let Some(base_path) = self.base_path() {
|
||||
if let Some(base_path) = self.trimmed_base_path() {
|
||||
env_vars.push((ASSET_ROOT_ENV.into(), base_path.to_string().into()));
|
||||
}
|
||||
env_vars.push((
|
||||
@@ -4898,7 +4898,7 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
|
||||
|
||||
// Add the base path to the head if this is a debug build
|
||||
if self.is_dev_build() {
|
||||
if let Some(base_path) = &self.base_path() {
|
||||
if let Some(base_path) = &self.trimmed_base_path() {
|
||||
head_resources.push_str(&format_base_path_meta_element(base_path));
|
||||
}
|
||||
}
|
||||
@@ -5044,14 +5044,16 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
|
||||
.filter(|_| matches!(self.bundle, BundleFormat::Web | BundleFormat::Server))
|
||||
}
|
||||
|
||||
/// Get the normalized base path for the application with `/` trimmed from both ends. If the base path is not set, this will return `.`.
|
||||
/// Get the normalized base path for the application with `/` trimmed from both ends.
|
||||
pub(crate) fn trimmed_base_path(&self) -> Option<&str> {
|
||||
self.base_path()
|
||||
.map(|p| p.trim_matches('/'))
|
||||
.filter(|p| !p.is_empty())
|
||||
}
|
||||
|
||||
/// Get the trimmed base path or `.` if no base path is set
|
||||
pub(crate) fn base_path_or_default(&self) -> &str {
|
||||
let trimmed_path = self.base_path().unwrap_or_default().trim_matches('/');
|
||||
if trimmed_path.is_empty() {
|
||||
"."
|
||||
} else {
|
||||
trimmed_path
|
||||
}
|
||||
self.trimmed_base_path().unwrap_or(".")
|
||||
}
|
||||
|
||||
/// Get the path to the package manifest directory
|
||||
|
||||
Reference in new issue
Block a user