Skip to content

Commit

Permalink
fix: path to assets inside lib
Browse files Browse the repository at this point in the history
  • Loading branch information
vinyguedess committed Jun 20, 2022
1 parent dd0bc8d commit e0252c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package geh

import (
"io/ioutil"
"path"
"path/filepath"
"runtime"
)

type DocEndpointHttpProtocol map[string]DocEndpoint
Expand Down Expand Up @@ -118,7 +121,15 @@ func addEndpointDefinitions(docs *DocEndpoint) {
func docsHandler(
request Request, response Response, _ ...interface{},
) *Response {
fileContent, _ := ioutil.ReadFile("./templates/swagger-ui/index.html")
_, filename, _, _ := runtime.Caller(0)
currentDirectory := filepath.Dir(filename)

fileContent, _ := ioutil.ReadFile(
path.Join(
currentDirectory,
"templates/swagger-ui/index.html",
),
)
return response.Html(string(fileContent))
}

Expand Down
7 changes: 6 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package geh

import (
"net/http"
"path/filepath"
"runtime"
"strings"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -43,8 +45,11 @@ func NewRouter(
Handler(docsSwaggerHandler),
).Methods(http.MethodGet)

_, filename, _, _ := runtime.Caller(0)
currentDirectory := filepath.Dir(filename)

muxRouter.PathPrefix("/assets/").Handler(
http.FileServer(http.Dir("./")),
http.FileServer(http.Dir(currentDirectory)),
)

return &GEHRouter{
Expand Down

0 comments on commit e0252c3

Please sign in to comment.