Skip to content

Commit

Permalink
Mount at the top level of the router
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed Sep 27, 2023
1 parent 2a1790d commit 3fbf066
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion http/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ type (
// NewMuxer returns a Muxer implementation based on a Chi router.
func NewMuxer() ResolverMuxer {
r := chi.NewRouter()
// RedirectSlashes must be mounted at the top level of the router.
// See. https://github.com/go-chi/chi/blob/1129e362d6cce6e3805e3bc8dfbaeb34b5129789/middleware/strip_test.go#L105-L107
r.Use(middleware.RedirectSlashes)
r.NotFound(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ctx := context.WithValue(req.Context(), AcceptTypeKey, req.Header.Get("Accept"))
enc := ResponseEncoder(ctx, w)
w.WriteHeader(http.StatusNotFound)
enc.Encode(NewErrorResponse(ctx, fmt.Errorf("404 page not found"))) // nolint:errcheck
}))
r.Use(middleware.RedirectSlashes)
return &mux{Router: r, wildcards: make(map[string]string)}
}

Expand Down

0 comments on commit 3fbf066

Please sign in to comment.