Fix the base path in the CLI (#2756)
This commit is contained in:
1 parent
4bf71111c8
commit
b8565e6de0
4 files changed
+37
-31
No files matched your search
@@ -39,16 +39,7 @@ pub(crate) fn process_assets(
|
||||
manifest: &AssetManifest,
|
||||
progress: &mut UnboundedSender<UpdateBuildProgress>,
|
||||
) -> anyhow::Result<()> {
|
||||
let static_asset_output_dir = PathBuf::from(
|
||||
config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.base_path
|
||||
.clone()
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let static_asset_output_dir = config.out_dir().join(static_asset_output_dir);
|
||||
let static_asset_output_dir = config.out_dir();
|
||||
|
||||
std::fs::create_dir_all(&static_asset_output_dir)
|
||||
.context("Failed to create static asset output directory")?;
|
||||
@@ -96,10 +87,14 @@ pub(crate) fn process_assets(
|
||||
pub(crate) struct AssetConfigDropGuard;
|
||||
|
||||
impl AssetConfigDropGuard {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(base_path: Option<&str>) -> Self {
|
||||
// Set up the collect asset config
|
||||
let base = match base_path {
|
||||
Some(base) => format!("/{}/", base.trim_matches('/')),
|
||||
None => "/".to_string(),
|
||||
};
|
||||
manganis_cli_support::Config::default()
|
||||
.with_assets_serve_location("/")
|
||||
.with_assets_serve_location(&base)
|
||||
.save();
|
||||
Self {}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,8 @@ impl BuildRequest {
|
||||
&dioxus_version,
|
||||
);
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
let _asset_guard = AssetConfigDropGuard::new();
|
||||
let _asset_guard =
|
||||
AssetConfigDropGuard::new(self.dioxus_crate.dioxus_config.web.app.base_path.as_deref());
|
||||
|
||||
// If this is a web, build make sure we have the web build tooling set up
|
||||
if self.web {
|
||||
@@ -163,7 +164,7 @@ impl BuildRequest {
|
||||
// Start Manganis linker intercept.
|
||||
let linker_args = vec![format!("{}", self.dioxus_crate.out_dir().display())];
|
||||
|
||||
// Don't block the main thread - magnanis should not be running its own std process but it's
|
||||
// Don't block the main thread - manganis should not be running its own std process but it's
|
||||
// fine to wrap it here at the top
|
||||
tokio::task::spawn_blocking(move || {
|
||||
manganis_cli_support::start_linker_intercept(
|
||||
@@ -196,11 +197,19 @@ impl BuildRequest {
|
||||
|
||||
let assets = if !self.build_arguments.skip_assets {
|
||||
let assets = asset_manifest(&self.dioxus_crate);
|
||||
// Collect assets
|
||||
process_assets(&self.dioxus_crate, &assets, progress)?;
|
||||
// Create the __assets_head.html file for bundling
|
||||
create_assets_head(&self.dioxus_crate, &assets)?;
|
||||
Some(assets)
|
||||
let dioxus_crate = self.dioxus_crate.clone();
|
||||
let mut progress = progress.clone();
|
||||
tokio::task::spawn_blocking(
|
||||
move || -> Result<Option<manganis_cli_support::AssetManifest>> {
|
||||
// Collect assets
|
||||
process_assets(&dioxus_crate, &assets, &mut progress)?;
|
||||
// Create the __assets_head.html file for bundling
|
||||
create_assets_head(&dioxus_crate, &assets)?;
|
||||
Ok(Some(assets))
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Builder {
|
||||
if let Err(err) = &res {
|
||||
let _ = tx.start_send(UpdateBuildProgress {
|
||||
stage: crate::builder::Stage::Finished,
|
||||
update: crate::builder::UpdateStage::Failed(err.to_string()),
|
||||
update: crate::builder::UpdateStage::Failed(format!("{err}")),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -360,21 +360,23 @@ fn setup_router(
|
||||
router = super::proxy::add_proxy(router, proxy_config)?;
|
||||
}
|
||||
|
||||
// Setup base path redirection
|
||||
if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
|
||||
let base_path = format!("/{}", base_path.trim_matches('/'));
|
||||
router = Router::new()
|
||||
.nest(&base_path, router)
|
||||
.fallback(get(move || async move {
|
||||
format!("Outside of the base path: {}", base_path)
|
||||
}));
|
||||
}
|
||||
|
||||
// server the dir if it's web, otherwise let the fullstack server itself handle it
|
||||
match platform {
|
||||
Platform::Web => {
|
||||
// Route file service to output the .wasm and assets if this is a web build
|
||||
router = router.nest_service("/", build_serve_dir(serve, config));
|
||||
let base_path = format!(
|
||||
"/{}",
|
||||
config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.base_path
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.trim_matches('/')
|
||||
);
|
||||
|
||||
router = router.nest_service(&base_path, build_serve_dir(serve, config));
|
||||
}
|
||||
Platform::Fullstack | Platform::StaticGeneration => {
|
||||
// For fullstack and static generation, forward all requests to the server
|
||||
|
||||
Reference in new issue
Block a user