Replies: 2 comments 3 replies
-
Fundamentally, a "smarter" behavior like what you've described is at odds with a middleware called "normalize path", so at the very least this should be a different middleware. Old-school web servers like Apache match up their path semantics with file system semantics because that's what they were doing - serving files via HTTP. But even in that landscape it seems frought to allow trailing slashes for files and missing slashes for directories. Maybe this is just my prescriptivism but if you mean to access a directory then there should be a slash. Modern web ideologies often use the term "resource" which is distinct from file systems and is more easily expressable without worrying about trailing slashes or not. This is why The All this said, I think it's possible to create a middleware that does some dynamic routing based on what's been registered in the router, but since routers are dynamic and nest-able, it would likely have some pretty sharp edges that make it just as difficult to use. |
Beta Was this translation helpful? Give feedback.
-
In case it helps your use case, I also want to point out that any method which accepts web::resource(["/foo", "/foo/"]) It's more boilerplate for sure, but it's a lesser known feature of the manual routing setups that might be useful. Similarly, for macro routing, |
Beta Was this translation helpful? Give feedback.
-
Currently,
NormalizePath
only supports either always appending a trailing slash or always trimming it before matching. I have a very specific use case that would be easier to implement with the following two features:TrailingSlash::TryAppend
).NormalizePath
to redirect over HTTP instead of just re-routing internally.This is basically the default behavior for file indexing in web servers like Apache: if the user goes to
/asdf
andasdf
is a folder, it redirects to/asdf/
. I think having this in theNormalizePath
middleware would be a nice quality of life improvement.Beta Was this translation helpful? Give feedback.
All reactions