Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware Chaining Not Respected by NotFound Handler #837

Open
sethgrid opened this issue Aug 6, 2023 · 1 comment · May be fixed by #888
Open

Middleware Chaining Not Respected by NotFound Handler #837

sethgrid opened this issue Aug 6, 2023 · 1 comment · May be fixed by #888
Labels

Comments

@sethgrid
Copy link

sethgrid commented Aug 6, 2023

I'm trying to set up a "catch all" route. Anything that goes to "catchall/some/other/thing" should go the allHandler. I have values that I am setting onto the context in my middleware. These values ONLY show up if I use r.HandleFunc("/", allHandler ) - if I only use the NotFound handler, then the middleware is never set.

router := chi.NewRouter()
router.Route("/catchall", func(r chi.Router) {
  r.Use(MiddlewareSetsContextValues)
  r.NotFound(allHandler)
  // uncomment the following so it works
  // r.HandleFunc("/", allHandler) // wont match ../some/other/thing
})

This feels like a bug - I'd have expected the r.HandleFunc to not be needed to register the middleware.

@pkieltyka
Copy link
Member

yes, this I’ve seen this confusion in the past — which is that at least one handler must be defined on a router for it to build the middleware stack.

@jtams jtams linked a pull request Dec 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants