Health server runs on 127.0.0.1:9999, fix #272
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (s *server) handleHealth(w http.ResponseWriter) {
|
||||
// TODO option to disable
|
||||
// TODO use mullvad API if current provider is Mullvad
|
||||
ips, err := s.lookupIP("github.com")
|
||||
var errorMessage string
|
||||
switch {
|
||||
case err != nil:
|
||||
errorMessage = fmt.Sprintf("cannot resolve github.com (%s)", err)
|
||||
case len(ips) == 0:
|
||||
errorMessage = "resolved no IP addresses for github.com"
|
||||
default: // success
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
s.logger.Warn(errorMessage)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
if _, err := w.Write([]byte(errorMessage)); err != nil {
|
||||
s.logger.Warn(err)
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,7 @@ func (s *server) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
|
||||
func (s *server) makeHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if s.logging && (r.Method != http.MethodGet || r.RequestURI != "/health") {
|
||||
s.logger.Info("HTTP %s %s", r.Method, r.RequestURI)
|
||||
}
|
||||
s.logger.Info("HTTP %s %s", r.Method, r.RequestURI)
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
switch r.RequestURI {
|
||||
@@ -80,8 +78,6 @@ func (s *server) makeHandler() http.HandlerFunc {
|
||||
s.handleGetPortForwarded(w)
|
||||
case "/openvpn/settings":
|
||||
s.handleGetOpenvpnSettings(w)
|
||||
case "/health":
|
||||
s.handleHealth(w)
|
||||
case "/updater/restart":
|
||||
s.updaterLooper.Restart()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
Reference in New Issue
Block a user