Skip to content

Commit

Permalink
create a separate handler on webServer so type assertion works in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korylprince committed Nov 16, 2023
1 parent 37e0144 commit 5d7cb2c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/op/server_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -88,14 +89,15 @@ 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
logger *slog.Logger
}

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 {
Expand Down

0 comments on commit 5d7cb2c

Please sign in to comment.