Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jan 23, 2025
1 parent fe8bcb1 commit cfd14f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion client/docs/embed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package docs

import "embed"
import (
"embed"
)

//go:embed swagger-ui
var SwaggerUI embed.FS
12 changes: 9 additions & 3 deletions server/v2/api/swagger/handler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package swagger

import (
"embed"
"io/fs"
"net/http"
)

type swaggerHandler struct {
swaggerFS embed.FS
swaggerFS fs.FS
}

func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand All @@ -19,5 +19,11 @@ func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

http.FileServer(http.FS(h.swaggerFS)).ServeHTTP(w, r)
root, err := fs.Sub(h.swaggerFS, "swagger-ui")
if err != nil {
http.Error(w, "failed to get swagger-ui from fs", http.StatusInternalServerError)
}

staticServer := http.FileServer(http.FS(root))
http.StripPrefix("/swagger/", staticServer).ServeHTTP(w, r)
}
4 changes: 2 additions & 2 deletions server/v2/api/swagger/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package swagger

import (
"context"
"embed"
"fmt"
"io/fs"
"net/http"

"cosmossdk.io/core/server"
Expand Down Expand Up @@ -31,7 +31,7 @@ type Server[T transaction.Tx] struct {
// New creates a new Swagger UI server
func New[T transaction.Tx](
logger log.Logger,
swaggerUI embed.FS,
swaggerUI fs.FS,
config server.ConfigMap,
cfgOptions ...CfgOption,
) (*Server[T], error) {
Expand Down

0 comments on commit cfd14f1

Please sign in to comment.