diff --git a/faucet.go b/faucet.go index 0a4bd95..43dd57a 100644 --- a/faucet.go +++ b/faucet.go @@ -93,18 +93,22 @@ func NewFaucet( f.mux.Use(corsMiddleware.Handler) } - // Set up additional middlewares - for _, middleware := range f.middlewares { - f.mux.Use(middleware) - } - // Register the health check handler f.mux.Get("/health", f.healthcheckHandler) - // Set up the request handlers - for _, handler := range f.handlers { - f.mux.Post(handler.Pattern, handler.HandlerFunc) - } + // Branch off another route group, so they don't influence + // "standard" routes like health + f.mux.Group(func(r chi.Router) { + // Apply user middlewares + for _, middleware := range f.middlewares { + r.Use(middleware) + } + + // Apply standard and custom route handlers + for _, handler := range f.handlers { + r.Post(handler.Pattern, handler.HandlerFunc) + } + }) return f, nil } diff --git a/faucet_test.go b/faucet_test.go index e1db3b9..75b9779 100644 --- a/faucet_test.go +++ b/faucet_test.go @@ -69,35 +69,6 @@ func TestFaucet_NewFaucet(t *testing.T) { assert.NoError(t, err) }) - t.Run("with middlewares", func(t *testing.T) { - t.Parallel() - - middlewares := []Middleware{ - func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // Example empty middleware - next.ServeHTTP(w, r) - }) - }, - } - - cfg := config.DefaultConfig() - cfg.CORSConfig = nil // disable CORS middleware - - f, err := NewFaucet( - &mockEstimator{}, - &mockClient{}, - WithConfig(cfg), - WithMiddlewares(middlewares), - ) - - require.NotNil(t, f) - assert.NoError(t, err) - - // Make sure the middleware was set - assert.Len(t, f.mux.Middlewares(), len(middlewares)) - }) - t.Run("with handlers", func(t *testing.T) { t.Parallel()