Skip to content

Commit 1530539

Browse files
Fix swagger docs routing (#685)
1 parent ff3d4ca commit 1530539

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

internal/http/http.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func New(apiService Service, FSS fs.FS, HFS http.FileSystem) *Service {
9090

9191
a.Router = mux.NewRouter()
9292
a.Router.Use(a.panicRecovery)
93+
a.Router.Use(otelmux.Middleware("thunderdome"))
9394

9495
if apiService.Config.PathPrefix != "" {
9596
a.Router = a.Router.PathPrefix(apiService.Config.PathPrefix).Subrouter()
@@ -104,9 +105,7 @@ func New(apiService Service, FSS fs.FS, HFS http.FileSystem) *Service {
104105
}
105106

106107
router := a.Router.PathPrefix("/").Subrouter()
107-
a.Router = router
108108
router.Use(secureMiddleware.Handler)
109-
router.Use(otelmux.Middleware("thunderdome"))
110109

111110
pokerSvc := poker.New(poker.Config{
112111
WriteWaitSec: a.Config.WebsocketConfig.WriteWaitSec,
@@ -517,7 +516,9 @@ func New(apiService Service, FSS fs.FS, HFS http.FileSystem) *Service {
517516
router.PathPrefix("/webhooks/subscriptions").Handler(a.SubscriptionSvc.HandleWebhook()).Methods("POST")
518517
}
519518

520-
a.registerOauthProviderEndpoints(authProviderConfigs)
519+
// have to pass router because of wonkyness with gorilla/mux and subrouters and middleware to support the Swagger UI and OIDC
520+
// @todo - refactor router to get away from gorilla/mux
521+
a.registerOauthProviderEndpoints(router, authProviderConfigs)
521522

522523
// static assets
523524
router.PathPrefix("/static/").Handler(http.StripPrefix(a.Config.PathPrefix, staticHandler))
@@ -532,7 +533,7 @@ func New(apiService Service, FSS fs.FS, HFS http.FileSystem) *Service {
532533
return a
533534
}
534535

535-
func (s *Service) registerOauthProviderEndpoints(providers []thunderdome.AuthProviderConfig) {
536+
func (s *Service) registerOauthProviderEndpoints(router *mux.Router, providers []thunderdome.AuthProviderConfig) {
536537
ctx := context.Background()
537538
var redirectBaseURL string
538539
var port string
@@ -550,8 +551,9 @@ func (s *Service) registerOauthProviderEndpoints(providers []thunderdome.AuthPro
550551

551552
for _, c := range providers {
552553
providerNameUrlPath := strings.ToLower(c.ProviderName)
553-
oauthLoginPathPrefix, _ := url.JoinPath("/oauth/", providerNameUrlPath, "/login")
554-
oauthCallbackPathPrefix, _ := url.JoinPath("/oauth/", providerNameUrlPath, "/callback")
554+
oauthPathPrefix := "/oauth/"
555+
oauthLoginPathPrefix, _ := url.JoinPath(oauthPathPrefix, providerNameUrlPath, "/login")
556+
oauthCallbackPathPrefix, _ := url.JoinPath(oauthPathPrefix, providerNameUrlPath, "/callback")
555557
callbackRedirectURL, _ := url.JoinPath(redirectBaseURL, oauthCallbackPathPrefix)
556558
authProvider, err := oauth.New(oauth.Config{
557559
AuthProviderConfig: c,
@@ -562,8 +564,8 @@ func (s *Service) registerOauthProviderEndpoints(providers []thunderdome.AuthPro
562564
if err != nil {
563565
panic(err)
564566
}
565-
s.Router.HandleFunc(oauthLoginPathPrefix, authProvider.HandleOAuth2Redirect()).Methods("GET")
566-
s.Router.HandleFunc(oauthCallbackPathPrefix, authProvider.HandleOAuth2Callback()).Methods("GET")
567+
router.HandleFunc(oauthLoginPathPrefix, authProvider.HandleOAuth2Redirect()).Methods("GET")
568+
router.HandleFunc(oauthCallbackPathPrefix, authProvider.HandleOAuth2Callback()).Methods("GET")
567569
}
568570
}
569571

0 commit comments

Comments
 (0)