From 5d7cb2c1a2346d36319f1c3a6293d25d8bb3a643 Mon Sep 17 00:00:00 2001 From: Kory Prince Date: Thu, 16 Nov 2023 17:49:13 -0600 Subject: [PATCH] create a separate handler on webServer so type assertion works in tests --- pkg/op/server_http.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/op/server_http.go b/pkg/op/server_http.go index 34a322fe..2220e448 100644 --- a/pkg/op/server_http.go +++ b/pkg/op/server_http.go @@ -38,8 +38,9 @@ func RegisterServer(server Server, endpoints Endpoints, options ...ServerOption) } ws.createRouter() + ws.handler = ws.router if ws.corsOpts != nil { - return cors.New(*ws.corsOpts).Handler(ws) + ws.handler = cors.New(*ws.corsOpts).Handler(ws.router) } return ws } @@ -88,6 +89,7 @@ func WithFallbackLogger(logger *slog.Logger) ServerOption { type webServer struct { server Server router *chi.Mux + handler http.Handler endpoints Endpoints decoder httphelper.Decoder corsOpts *cors.Options @@ -95,7 +97,7 @@ type webServer struct { } func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { - s.router.ServeHTTP(w, r) + s.handler.ServeHTTP(w, r) } func (s *webServer) getLogger(ctx context.Context) *slog.Logger {