1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-10 00:43:36 +02:00
pocketbase/apis/health.go

39 lines
856 B
Go
Raw Normal View History

2022-12-11 17:27:46 +02:00
package apis
import (
2022-12-11 17:32:43 +02:00
"net/http"
2022-12-11 17:27:46 +02:00
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase/core"
)
// bindHealthApi registers the health api endpoint.
func bindHealthApi(app core.App, rg *echo.Group) {
api := healthApi{app: app}
subGroup := rg.Group("/health")
subGroup.GET("", api.healthCheck)
}
type healthApi struct {
app core.App
}
2023-05-13 21:10:14 +02:00
type healthCheckResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
CanBackup bool `json:"canBackup"`
} `json:"data"`
}
2022-12-11 17:27:46 +02:00
// healthCheck returns a 200 OK response if the server is healthy.
func (api *healthApi) healthCheck(c echo.Context) error {
2023-05-13 21:10:14 +02:00
resp := new(healthCheckResponse)
resp.Code = http.StatusOK
resp.Message = "API is healthy."
resp.Data.CanBackup = !api.app.Cache().Has(core.CacheKeyActiveBackup)
2022-12-11 17:32:43 +02:00
2023-05-13 21:10:14 +02:00
return c.JSON(http.StatusOK, resp)
2022-12-11 17:27:46 +02:00
}