Skip to content

Commit

Permalink
Merge pull request #64 from calvinmclean/fix/middleware
Browse files Browse the repository at this point in the history
Apply default middleware before base route
  • Loading branch information
calvinmclean committed May 5, 2024
2 parents afa42ab + c64c3fd commit 25f31ca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (a *API[T]) Route(r chi.Router) error {
}
})

// Only set these middleware for root-level API
if a.parent == nil {
a.DefaultMiddleware(r)
}

for _, m := range a.middlewares {
r.Use(m)
}
Expand All @@ -80,11 +85,6 @@ func (a *API[T]) Route(r chi.Router) error {

var returnErr error
r.Route(a.base, func(r chi.Router) {
// Only set these middleware for root-level API
if a.parent == nil {
a.DefaultMiddleware(r)
}

if a.rootAPI {
returnErr = a.rootAPIRoutes(r)
return
Expand Down

0 comments on commit 25f31ca

Please sign in to comment.