Skip to content

Middleware Chaining Not Respected by NotFound Handler #837

Open
@sethgrid

Description

@sethgrid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions