@@ -32,6 +32,7 @@ type route struct {
3232
3333// site is the minimal interface for accessing site methods
3434type site interface {
35+ Healthy () bool
3536 Configuration () core.SiteConfiguration
3637 LoadPoints () []* core.LoadPoint
3738 loadpoint
@@ -100,10 +101,15 @@ func jsonResponse(w http.ResponseWriter, r *http.Request, content interface{}) {
100101}
101102
102103// HealthHandler returns current charge mode
103- func HealthHandler () http.HandlerFunc {
104+ func HealthHandler (site site ) http.HandlerFunc {
104105 return func (w http.ResponseWriter , r * http.Request ) {
105- res := struct { OK bool }{OK : true }
106- jsonResponse (w , r , res )
106+ if ! site .Healthy () {
107+ w .WriteHeader (http .StatusInternalServerError )
108+ return
109+ }
110+
111+ w .WriteHeader (http .StatusOK )
112+ fmt .Fprintln (w , "OK" )
107113 }
108114}
109115
@@ -231,7 +237,7 @@ type HTTPd struct {
231237// NewHTTPd creates HTTP server with configured routes for loadpoint
232238func NewHTTPd (url string , site site , hub * SocketHub , cache * util.Cache ) * HTTPd {
233239 var routes = map [string ]route {
234- "health" : {[]string {"GET" }, "/health" , HealthHandler ()},
240+ "health" : {[]string {"GET" }, "/health" , HealthHandler (site )},
235241 "config" : {[]string {"GET" }, "/config" , ConfigHandler (site )},
236242 "templates" : {[]string {"GET" }, "/config/templates/{class:[a-z]+}" , TemplatesHandler ()},
237243 "state" : {[]string {"GET" }, "/state" , StateHandler (cache )},
0 commit comments