Skip to content

Commit

Permalink
(BEDS-295) move docs embed var
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly committed Sep 10, 2024
1 parent c339f46 commit 571e027
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ local_deployment/elconfig.json
local_deployment/.env
__gitignore
cmd/playground
docs
pkg/api/docs/swagger.json
6 changes: 6 additions & 0 deletions backend/pkg/api/docs/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package docs

import "embed"

//go:embed *
var Files embed.FS
7 changes: 2 additions & 5 deletions backend/pkg/api/router.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package api

import (
"embed"
"net/http"
"regexp"

dataaccess "github.com/gobitfly/beaconchain/pkg/api/data_access"
"github.com/gobitfly/beaconchain/pkg/api/docs"
handlers "github.com/gobitfly/beaconchain/pkg/api/handlers"
"github.com/gobitfly/beaconchain/pkg/commons/log"
"github.com/gobitfly/beaconchain/pkg/commons/metrics"
Expand All @@ -21,9 +21,6 @@ type endpoint struct {
InternalHander func(w http.ResponseWriter, r *http.Request)
}

//go:embed docs/*
var docFiles embed.FS

func NewApiRouter(dataAccessor dataaccess.DataAccessor, cfg *types.Config) *mux.Router {
router := mux.NewRouter()
apiRouter := router.PathPrefix("/api").Subrouter()
Expand All @@ -44,7 +41,7 @@ func NewApiRouter(dataAccessor dataaccess.DataAccessor, cfg *types.Config) *mux.
addRoutes(handlerService, publicRouter, internalRouter, cfg)

// serve static files
publicRouter.PathPrefix("/docs/").Handler(http.StripPrefix("/api/v2/", http.FileServer(http.FS(docFiles))))
publicRouter.PathPrefix("/docs/").Handler(http.StripPrefix("/api/v2/docs/", http.FileServer(http.FS(docs.Files))))
router.Use(metrics.HttpMiddleware)

return router
Expand Down

0 comments on commit 571e027

Please sign in to comment.