Fix base path on web and fullstack (#3247)
* Create a crate for constant serialization of config structs for manganis * use SerializeConst for the image asset builder * switch to a declarative macro for assets * clean up asset macro a bit * add serializable options for each asset type * serialize const vec * Add unique path formatting * implement the new manganis macro * optimize assets in the CLI * Fix clippy * Fix assets with dioxus formattable * reduce fuzzing test limits * use the new syntax in examples * fix formatting * Final doc and test pass on const-serialize * fix avif support * Fix manganis doc tests * cache asset optimization * Split out asset and bundled asset * make hash pointer width independent * remove const serialize cargo lock * Fix manganis macro docs * all tests passing * add constvec::is_empty method to fix clippy lint * remove nasm feature * simplify test_rsplit_once test so typos passes * fix range syntax for stable * revert example change from clippy fix * remove dioxus-static-site-generation workspace dependency * always accept unix paths * fix windows path seperator * fix folder asset hash * Optimize assets in a blocking task * Fix asset options docs * Document Asset and BundledAsset * move manganis back into it's own folder * simplify the linker macro a bit * add more docs to AssetParser expansion * fix manganis core doc test * add image format helpers * Fill in new cargo.tomls * fix folders with explicit options * Split by both unix and windows path separators and take the smallest one * fix string length * Fix base path on web and fullstack * Fix assets with base path * fix fullstack base route with trailing slash * fix clippy
This commit is contained in:
1 parent
1e8693a0e8
commit
3d62fbf021
20 files changed
+254
-41
No files matched your search
@@ -2,8 +2,16 @@
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::{Request, State},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use dioxus_cli_config::base_path;
|
||||
use dioxus_lib::prelude::*;
|
||||
|
||||
use crate::server::{render_handler, RenderHandleState, SSRState};
|
||||
|
||||
/// Launch a fullstack app with the given root component, contexts, and config.
|
||||
#[allow(unused)]
|
||||
pub fn launch(
|
||||
@@ -60,9 +68,37 @@ pub fn launch(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut router =
|
||||
let mut base_path = base_path();
|
||||
let config = platform_config.as_ref().ok().cloned();
|
||||
let dioxus_router =
|
||||
axum::Router::new().serve_dioxus_application(TryIntoResult(platform_config), root);
|
||||
let mut router;
|
||||
match base_path.as_deref() {
|
||||
Some(base_path) => {
|
||||
let base_path = base_path.trim_matches('/');
|
||||
// If there is a base path, nest the router under it and serve the root route manually
|
||||
// Nesting a route in axum only serves /base_path or /base_path/ not both
|
||||
router = axum::Router::new().nest(&format!("/{base_path}/"), dioxus_router);
|
||||
async fn root_render_handler(
|
||||
state: State<RenderHandleState>,
|
||||
mut request: Request<Body>,
|
||||
) -> impl IntoResponse {
|
||||
// The root of the base path always looks like the root from dioxus fullstack
|
||||
*request.uri_mut() = "/".parse().unwrap();
|
||||
render_handler(state, request).await
|
||||
}
|
||||
if let Some(cfg) = config {
|
||||
let ssr_state = SSRState::new(&cfg);
|
||||
router = router.route(
|
||||
&format!("/{base_path}"),
|
||||
axum::routing::method_routing::get(root_render_handler).with_state(
|
||||
RenderHandleState::new(cfg, root).with_ssr_state(ssr_state),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
None => router = dioxus_router,
|
||||
}
|
||||
|
||||
let router = router.into_make_service();
|
||||
let listener = tokio::net::TcpListener::bind(address).await.unwrap();
|
||||
|
||||
Reference in new issue
Block a user