-
-
Notifications
You must be signed in to change notification settings - Fork 392
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Request
Is your feature request related to a problem? Please describe.
I want to configure a 301 Moved Permanently redirect for paths with a trailing slash, for example I want a request to /path/ to be redirected to /path, and apply this to all routes used by the app.
Describe the solution you'd like
Configuration option normalize_paths. If set to true, Loco should add corresponding redirects for me.
Describe alternatives you've considered
AFAIK in Axum there are two options:
- Use
RouterExt'sroute_with_tsr. It is not possible to use this trait when using Loco'sRoutes. - Use
NormalizePathmiddleware to remove the trailing slash before routing. This requires wrapping the middleware around the entireRouter, which is not directly exposed by Loco'sHooksbefore serving. The only way to accomplish that I see is to overrideservewith my own impl. Also this does not directly achieve what I want, because it will route both paths to the same handler instead of issuing a redirect.
Since Routes API is public, I can also iterate over handlers and create redirects manually myself, but this seems tedious and it would be really nice to have support for this from the framework.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request