From 69b39286e3ef2c8e7d110fcf57a73f033046d879 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 13 Oct 2020 13:03:25 +0200 Subject: [PATCH] Fix getting logs for landingpage (#9) * Fix getting logs for landingpage * fix return --- http.go | 15 +++++++++------ main.go | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/http.go b/http.go index c6cf4a8..a5dec61 100644 --- a/http.go +++ b/http.go @@ -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) { @@ -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 } diff --git a/main.go b/main.go index 48ef44e..a0ae154 100644 --- a/main.go +++ b/main.go @@ -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)