Skip to content

Commit

Permalink
Merge pull request #195 from Senyoret1/V1-endpoint
Browse files Browse the repository at this point in the history
Use /api/v1/ prefixed endpoints
  • Loading branch information
gz-c authored May 22, 2018
2 parents 53dee8d + 8598f98 commit f11da8a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Environment options:
CLI Options:
* -api-only - Don't serve static content from ./dist, only proxy the skycoin node
* -use-unversioned-api - Use the deprecated unversioned API endpoints without /api/v1 prefix, when communicating with the node
Run the explorer and navigate to http://127.0.0.1:8001/api.html for API documentation.
Expand Down Expand Up @@ -50,10 +51,11 @@ const (
)

var (
explorerHost = "" // override with envvar EXPLORER_HOST. Must not have scheme
skycoinAddr *url.URL // override with envvar SKYCOIN_ADDR. Must have scheme, e.g. http://
apiOnly bool // set to true with -api-only cli flag
verify bool // set to true with -verify cli flag. Check init() conditions and quits.
explorerHost = "" // override with envvar EXPLORER_HOST. Must not have scheme
skycoinAddr *url.URL // override with envvar SKYCOIN_ADDR. Must have scheme, e.g. http://
apiOnly bool // set to true with -api-only cli flag
useUnversionedAPI bool // calls unversioned API endpoints on the node (without the /api/v1 prefix)
verify bool // set to true with -verify cli flag. Check init() conditions and quits.
)

func init() {
Expand Down Expand Up @@ -85,6 +87,7 @@ func init() {
}

flag.BoolVar(&apiOnly, "api-only", false, "Only run the API, don't serve static content")
flag.BoolVar(&useUnversionedAPI, "use-unversioned-api", false, "Use the deprecated unversioned API endpoints without /api/v1 prefix, when communicating with the node")
flag.BoolVar(&verify, "verify", false, "Run init() checks and quit")
flag.Parse()

Expand All @@ -95,6 +98,10 @@ func init() {
if apiOnly {
log.Println("Running in api-only mode")
}

if useUnversionedAPI {
log.Println("Using the deprecated unversioned API endpoints")
}
}

func buildSkycoinURL(path string, query url.Values) string {
Expand All @@ -103,6 +110,10 @@ func buildSkycoinURL(path string, query url.Values) string {
rawQuery = query.Encode()
}

if !useUnversionedAPI {
path = "/api/v1" + path
}

u := &url.URL{
Scheme: skycoinAddr.Scheme,
Host: skycoinAddr.Host,
Expand Down

0 comments on commit f11da8a

Please sign in to comment.