Improve the base_path story (#2381)
* Improve the base_path story * allow base path routes without trailing slash * remove note about trailing / * fix clippy empty docs --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
472031d1f5
commit
010dcf9533
6 files changed
+31
-21
No files matched your search
@@ -571,7 +571,7 @@ pub fn gen_page(config: &CrateConfig, manifest: Option<&AssetManifest>, serve: b
|
||||
}
|
||||
|
||||
let base_path = match &config.dioxus_config.web.app.base_path {
|
||||
Some(path) => path,
|
||||
Some(path) => path.trim_matches('/'),
|
||||
None => ".",
|
||||
};
|
||||
let app_name = &config.dioxus_config.application.name;
|
||||
|
||||
@@ -116,21 +116,26 @@ async fn start_server(
|
||||
router: axum::Router,
|
||||
start_browser: bool,
|
||||
rustls: Option<axum_server::tls_rustls::RustlsConfig>,
|
||||
_config: &CrateConfig,
|
||||
config: &CrateConfig,
|
||||
) -> Result<()> {
|
||||
// If plugins, call on_serve_start event
|
||||
#[cfg(feature = "plugin")]
|
||||
crate::plugin::PluginManager::on_serve_start(_config)?;
|
||||
crate::plugin::PluginManager::on_serve_start(config)?;
|
||||
|
||||
// Bind the server to `[::]` and it will LISTEN for both IPv4 and IPv6. (required IPv6 dual stack)
|
||||
let addr: SocketAddr = format!("0.0.0.0:{}", port).parse().unwrap();
|
||||
|
||||
// Open the browser
|
||||
if start_browser {
|
||||
match rustls {
|
||||
Some(_) => _ = open::that(format!("https://localhost:{port}")),
|
||||
None => _ = open::that(format!("http://localhost:{port}")),
|
||||
}
|
||||
let protocol = match rustls {
|
||||
Some(_) => "https",
|
||||
None => "http",
|
||||
};
|
||||
let base_path = match config.dioxus_config.web.app.base_path.as_deref() {
|
||||
Some(base_path) => format!("/{}", base_path.trim_matches('/')),
|
||||
None => "".to_owned(),
|
||||
};
|
||||
_ = open::that(format!("{protocol}://localhost:{port}{base_path}"));
|
||||
}
|
||||
|
||||
let svc = router.into_make_service();
|
||||
|
||||
@@ -62,8 +62,8 @@ pub async fn setup_router(
|
||||
.and_then(move |response| async move { Ok(no_cache(file_service_config, response)) })
|
||||
.service(ServeDir::new(config.out_dir()));
|
||||
|
||||
// Setup websocket
|
||||
let mut router = Router::new().route("/_dioxus/ws", get(ws_handler));
|
||||
// Setup router
|
||||
let mut router = Router::new();
|
||||
|
||||
// Setup proxy
|
||||
for proxy_config in config.dioxus_config.web.proxy {
|
||||
@@ -83,7 +83,7 @@ pub async fn setup_router(
|
||||
router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
|
||||
let base_path = format!("/{}", base_path.trim_matches('/'));
|
||||
Router::new()
|
||||
.route(&base_path, axum::routing::any_service(router))
|
||||
.nest(&base_path, router)
|
||||
.fallback(get(move || {
|
||||
let base_path = base_path.clone();
|
||||
async move { format!("Outside of the base path: {}", base_path) }
|
||||
@@ -92,6 +92,9 @@ pub async fn setup_router(
|
||||
router
|
||||
};
|
||||
|
||||
// Setup websocket
|
||||
router = router.route("/_dioxus/ws", get(ws_handler));
|
||||
|
||||
// Setup routes
|
||||
router = router
|
||||
.route("/_dioxus/hot_reload", get(hot_reload_handler))
|
||||
|
||||
Reference in new issue
Block a user