Skip to content

Commit

Permalink
fix(deps): axum 0.6.13 does not allow nesting fallback routers under /
Browse files Browse the repository at this point in the history
Explicitly specify a fallback for the outer router, rather than
nesting another router under / which has a fallback set.
  • Loading branch information
alcroito committed May 18, 2023
1 parent 415009c commit 2e3af64
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions crates/dyndns/src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::web::routes::domain_record_ip_changes::list_domain_record_ip_changes;
use crate::web::static_server::serve_static_decisor;

const WEB_API_PATH_URL_PART: &str = "/api/v1";
const WEB_APP_PATH_URL_PART: &str = "/";

pub fn get_final_router(state: WebServerState) -> Router {
#[allow(unused_mut)]
Expand Down Expand Up @@ -64,13 +63,14 @@ fn get_pure_router_and_open_api() -> (Router<WebServerState>, OpenApi) {

let mut api = OpenApi::default();

let static_router = static_routes().into();
let api_router = api_routes();

let final_router = ApiRouter::new()
.nest(WEB_API_PATH_URL_PART, api_router)
.nest(WEB_APP_PATH_URL_PART, static_router)
.nest("/docs", docs_routes())
// Explicitly set fallback on outer router, to avoid
// https://github.com/tokio-rs/axum/discussions/2012
.fallback(serve_static_decisor)
.finish_api_with(&mut api, api_docs);
(final_router, api)
}
Expand All @@ -85,10 +85,6 @@ fn api_routes() -> ApiRouter<WebServerState> {
)
}

fn static_routes() -> Router<WebServerState> {
Router::new().fallback(serve_static_decisor)
}

#[cfg(test)]
mod tests {
use serde::Serialize;
Expand Down

0 comments on commit 2e3af64

Please sign in to comment.