Skip to content

Commit

Permalink
Fix getting logs for landingpage (#9)
Browse files Browse the repository at this point in the history
* Fix getting logs for landingpage

* fix return
  • Loading branch information
pvizeli authored Oct 13, 2020
1 parent c5b27ae commit 69b3928
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ func checkNetwork(r *http.Request) bool {
return false
}

// If supervisor is down
if !supervisorPing() {
log.Printf("API is disabled / Supervisor is running - %s", remote)
return true
return true
}

func apiPing(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}

return false
w.WriteHeader(http.StatusOK)
}

func apiLogs(w http.ResponseWriter, r *http.Request) {
Expand All @@ -51,7 +54,7 @@ func apiLogs(w http.ResponseWriter, r *http.Request) {
}

func apiRestart(w http.ResponseWriter, r *http.Request) {
if !checkNetwork(r) {
if !checkNetwork(r) || supervisorPing() {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
indexTemplate = template.Must(template.ParseFiles(wwwRoot + "/index.html"))

http.HandleFunc("/", statusIndex)
http.HandleFunc("/ping", apiPing)
http.HandleFunc("/logs", apiLogs)
http.HandleFunc("/restart", apiRestart)

Expand Down

0 comments on commit 69b3928

Please sign in to comment.