You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I create a middleware to log the id URL parameter, which exists in the route I request, the value is always empty. I do get a value inside the handler itself
This behavior is due to the way the chi router handles middleware and route patterns. When you register a middleware using r.Use() at the root level, the middleware is applied to all routes, including routes that do not have any URL parameters. As a result, when the middleware tries to extract the "id" parameter using chi.URLParam(r, "id"), it doesn't find it because the current route doesn't have an "id" parameter.
The behavior you describe would be what I would expect to be the behavior, but the problem is that when I execute an HTTP request for a route which does have an id parameter, it won't be able to find the parameter even though the route does contain a parameter.
When I create a middleware to log the
id
URL parameter, which exists in the route I request, the value is always empty. I do get a value inside the handler itselfWhen I move this code to a
Group
, the URL param will become available inside the middleware.I think this behavior is quite strange and prone to errors
Tested with the latest version (5.0.11)
The text was updated successfully, but these errors were encountered: