Skip to content

Commit 69b3928

Browse files
authored
Fix getting logs for landingpage (#9)
* Fix getting logs for landingpage * fix return
1 parent c5b27ae commit 69b3928

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

http.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ func checkNetwork(r *http.Request) bool {
2020
return false
2121
}
2222

23-
// If supervisor is down
24-
if !supervisorPing() {
25-
log.Printf("API is disabled / Supervisor is running - %s", remote)
26-
return true
23+
return true
24+
}
25+
26+
func apiPing(w http.ResponseWriter, r *http.Request) {
27+
if r.Method != "GET" {
28+
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
29+
return
2730
}
2831

29-
return false
32+
w.WriteHeader(http.StatusOK)
3033
}
3134

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

5356
func apiRestart(w http.ResponseWriter, r *http.Request) {
54-
if !checkNetwork(r) {
57+
if !checkNetwork(r) || supervisorPing() {
5558
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
5659
return
5760
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func main() {
4141
indexTemplate = template.Must(template.ParseFiles(wwwRoot + "/index.html"))
4242

4343
http.HandleFunc("/", statusIndex)
44+
http.HandleFunc("/ping", apiPing)
4445
http.HandleFunc("/logs", apiLogs)
4546
http.HandleFunc("/restart", apiRestart)
4647

0 commit comments

Comments
 (0)