File tree Expand file tree Collapse file tree 2 files changed +13
-38
lines changed
Expand file tree Collapse file tree 2 files changed +13
-38
lines changed Original file line number Diff line number Diff line change @@ -93,18 +93,22 @@ func NewFaucet(
9393 f .mux .Use (corsMiddleware .Handler )
9494 }
9595
96- // Set up additional middlewares
97- for _ , middleware := range f .middlewares {
98- f .mux .Use (middleware )
99- }
100-
10196 // Register the health check handler
10297 f .mux .Get ("/health" , f .healthcheckHandler )
10398
104- // Set up the request handlers
105- for _ , handler := range f .handlers {
106- f .mux .Post (handler .Pattern , handler .HandlerFunc )
107- }
99+ // Branch off another route group, so they don't influence
100+ // "standard" routes like health
101+ f .mux .Group (func (r chi.Router ) {
102+ // Apply user middlewares
103+ for _ , middleware := range f .middlewares {
104+ r .Use (middleware )
105+ }
106+
107+ // Apply standard and custom route handlers
108+ for _ , handler := range f .handlers {
109+ r .Post (handler .Pattern , handler .HandlerFunc )
110+ }
111+ })
108112
109113 return f , nil
110114}
Original file line number Diff line number Diff line change @@ -69,35 +69,6 @@ func TestFaucet_NewFaucet(t *testing.T) {
6969 assert .NoError (t , err )
7070 })
7171
72- t .Run ("with middlewares" , func (t * testing.T ) {
73- t .Parallel ()
74-
75- middlewares := []Middleware {
76- func (next http.Handler ) http.Handler {
77- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
78- // Example empty middleware
79- next .ServeHTTP (w , r )
80- })
81- },
82- }
83-
84- cfg := config .DefaultConfig ()
85- cfg .CORSConfig = nil // disable CORS middleware
86-
87- f , err := NewFaucet (
88- & mockEstimator {},
89- & mockClient {},
90- WithConfig (cfg ),
91- WithMiddlewares (middlewares ),
92- )
93-
94- require .NotNil (t , f )
95- assert .NoError (t , err )
96-
97- // Make sure the middleware was set
98- assert .Len (t , f .mux .Middlewares (), len (middlewares ))
99- })
100-
10172 t .Run ("with handlers" , func (t * testing.T ) {
10273 t .Parallel ()
10374
You can’t perform that action at this time.
0 commit comments