diff --git a/cmd/bnsapi/handlers/handlers.go b/cmd/bnsapi/handlers/handlers.go index f6ee3c3..3c290f9 100644 --- a/cmd/bnsapi/handlers/handlers.go +++ b/cmd/bnsapi/handlers/handlers.go @@ -6,10 +6,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/iov-one/bns/cmd/bnsapi/client" - "github.com/iov-one/bns/cmd/bnsapi/util" - "github.com/iov-one/weave/cmd/bnsd/x/username" - "github.com/iov-one/weave/x/cash" "html/template" "log" "math" @@ -19,6 +15,11 @@ import ( "strconv" "strings" + "github.com/iov-one/bns/cmd/bnsapi/client" + "github.com/iov-one/bns/cmd/bnsapi/util" + "github.com/iov-one/weave/cmd/bnsd/x/username" + "github.com/iov-one/weave/x/cash" + "github.com/iov-one/weave" "github.com/iov-one/weave/cmd/bnsd/x/account" "github.com/iov-one/weave/cmd/bnsd/x/termdeposit" @@ -566,9 +567,7 @@ func lastChunk(path string) string { } // DefaultHandler is used to handle the request that no other handler wants. -type DefaultHandler struct { - HostPort string -} +type DefaultHandler struct{} var wEndpoint = []string{ "/account/accounts/?domainKey=_&ownerKey=_", @@ -580,14 +579,6 @@ var wEndpoint = []string{ "/termdeposit/deposits/?depositor=_&contract=_&contract_id=?_offset=_", } -func endpointsWithDomain(domain string, endpoints []string) []string { - var eps []string - for _, e := range endpoints { - eps = append(eps, "http://"+domain+e) - } - return eps -} - var withoutParamEndpoint = []string{ "/info/", "/account/accounts/{accountKey}", @@ -596,7 +587,6 @@ var withoutParamEndpoint = []string{ } type endpoints struct { - HostPort string WithParam []string WithoutParam []string } @@ -615,7 +605,7 @@ var availableEndpointsTempl = template.Must(template.New("").Parse(` {{end}}

Swagger documentation:

-http://{{ .HostPort}}/docs
+/docs
`)) func (h *DefaultHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -627,9 +617,8 @@ func (h *DefaultHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } eps := endpoints{ - HostPort: h.HostPort, - WithParam: endpointsWithDomain(h.HostPort, wEndpoint), - WithoutParam: endpointsWithDomain(h.HostPort, withoutParamEndpoint), + WithParam: wEndpoint, + WithoutParam: withoutParamEndpoint, } if err := availableEndpointsTempl.Execute(w, eps); err != nil { diff --git a/cmd/bnsapi/main.go b/cmd/bnsapi/main.go index c156039..1ba79c1 100644 --- a/cmd/bnsapi/main.go +++ b/cmd/bnsapi/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/iov-one/bns/cmd/bnsapi/client" "github.com/iov-one/bns/cmd/bnsapi/docs" "github.com/iov-one/bns/cmd/bnsapi/handlers" @@ -27,8 +28,6 @@ import ( type Configuration struct { HTTP string Tendermint string - // HostPort is used for swagger docs configuration - HostPort string } // @title BNSAPI documentation @@ -39,9 +38,7 @@ func main() { conf := Configuration{ HTTP: env("HTTP", ":8000"), - Tendermint: env("TENDERMINT", "http://localhost:26657"), - HostPort: env("HOST_PORT", "localhost:80"), - } + Tendermint: env("TENDERMINT", "http://localhost:26657")} if err := run(conf); err != nil { log.Fatal(err) @@ -92,12 +89,11 @@ func run(conf Configuration) error { rt.Handle("/gov/proposals", &handlers.GovProposalsHandler{Bns: bnscli}) rt.Handle("/gov/votes", &handlers.GovVotesHandler{Bns: bnscli}) rt.Handle("/gconf/", &handlers.GconfHandler{Bns: bnscli, Confs: gconfConfigurations}) - rt.Handle("/", &handlers.DefaultHandler{HostPort: conf.HostPort}) + rt.Handle("/", &handlers.DefaultHandler{}) docs.SwaggerInfo.Title = "IOV Name Service Rest API" docs.SwaggerInfo.Version = util.BuildVersion - docs.SwaggerInfo.Host = conf.HostPort - docsUrl := fmt.Sprintf("http://%s/docs/doc.json", conf.HostPort) + docsUrl := fmt.Sprintf("doc.json") rt.Handle("/docs/", httpSwagger.Handler(httpSwagger.URL(docsUrl))) if err := http.ListenAndServe(conf.HTTP, rt); err != nil {