Skip to content

Commit

Permalink
fix: render_route error message and matching of non standard routes (
Browse files Browse the repository at this point in the history
  • Loading branch information
benwis authored Sep 29, 2023
1 parent 609afce commit d7fff5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion integrations/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/leptos-rs/leptos"
description = "Axum integrations for the Leptos web framework."

[dependencies]
axum = { version = "0.6", default-features = false }
axum = { version = "0.6", default-features = false, features=["matched-path"] }
futures = "0.3"
http = "0.2.8"
hyper = "0.14.23"
Expand Down
21 changes: 13 additions & 8 deletions integrations/axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use axum::{
body::{Body, Bytes, Full, StreamBody},
extract::{FromRef, FromRequestParts, Path, RawQuery},
extract::{FromRef, FromRequestParts, MatchedPath, Path, RawQuery},
http::{
header::{HeaderName, HeaderValue},
HeaderMap, Request, StatusCode,
Expand Down Expand Up @@ -644,17 +644,22 @@ where
);

move |req| {
let uri = req.uri();
// 1. Process route to match the values in routeListing
let path = uri.path();
let path = req
.extensions()
.get::<MatchedPath>()
.expect("Failed to get Axum router rule")
.as_str();
// 2. Find RouteListing in paths. This should probably be optimized, we probably don't want to
// search for this every time
let listing: &RouteListing =
paths.iter().find(|r| r.path() == path).expect(
"Failed to find the route {path} requested by the user. This \
suggests that the routing rules in the Router that call this \
handler needs to be edited!",
);
paths.iter().find(|r| r.path() == path).unwrap_or_else(|| {
panic!(
"Failed to find the route {path} requested by the user. \
This suggests that the routing rules in the Router that \
call this handler needs to be edited!"
)
});
// 3. Match listing mode against known, and choose function
match listing.mode() {
SsrMode::OutOfOrder => ooo(req),
Expand Down

0 comments on commit d7fff5a

Please sign in to comment.