File tree 2 files changed +13
-38
lines changed
2 files changed +13
-38
lines changed Original file line number Diff line number Diff line change @@ -93,18 +93,22 @@ func NewFaucet(
93
93
f .mux .Use (corsMiddleware .Handler )
94
94
}
95
95
96
- // Set up additional middlewares
97
- for _ , middleware := range f .middlewares {
98
- f .mux .Use (middleware )
99
- }
100
-
101
96
// Register the health check handler
102
97
f .mux .Get ("/health" , f .healthcheckHandler )
103
98
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
+ })
108
112
109
113
return f , nil
110
114
}
Original file line number Diff line number Diff line change @@ -69,35 +69,6 @@ func TestFaucet_NewFaucet(t *testing.T) {
69
69
assert .NoError (t , err )
70
70
})
71
71
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
-
101
72
t .Run ("with handlers" , func (t * testing.T ) {
102
73
t .Parallel ()
103
74
You can’t perform that action at this time.
0 commit comments