Skip to content

Commit

Permalink
feat(public): add status page (#61)
Browse files Browse the repository at this point in the history
* add status page which shows if the server can operate normaly or if the database connection is broken

Closes: #26

Co-authored-by: Stefan Jacobi <[email protected]>
  • Loading branch information
shentschel and Stefan Jacobi authored Apr 25, 2024
1 parent c1b0cce commit c0af643
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions server/api/handler/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package handler

import (
"github.com/labstack/echo/v4"
"github.com/teamhanko/passkey-server/persistence"
"net/http"
)

type StatusHandler interface {
Get(ctx echo.Context) error
}

type statusHandler struct {
persister persistence.Persister
}

func NewStatusHandler(persister persistence.Persister) StatusHandler {
return &statusHandler{persister: persister}
}

func (sh *statusHandler) Get(ctx echo.Context) error {
// random query to check DB connectivity
_, err := sh.persister.GetJwkPersister(nil).GetAll()
if err != nil {
return ctx.Render(http.StatusInternalServerError, "status", map[string]bool{"dbError": true})
}

return ctx.Render(http.StatusOK, "status", nil)
}
3 changes: 3 additions & 0 deletions server/api/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func NewMainRouter(cfg *config.Config, persister persistence.Persister, authenti
// Validator
main.Validator = validators.NewCustomValidator()

statusHandler := handler.NewStatusHandler(persister)
main.GET("/", statusHandler.Get)

rootGroup := main.Group("/:tenant_id", passkeyMiddleware.TenantMiddleware(persister))
tenantGroup := rootGroup.Group(
"",
Expand Down
2 changes: 1 addition & 1 deletion server/api/template/templates/status.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p>❌ API is not functioning properly due to database connectivity problems.</p>
{{else}}
<p>✅ API is running.</p>
<p>Check integration guides on <a href="https://docs.hanko.io" target="_blank">docs.hanko.io</a></p>
<p>Check integration guides on <a href="https://docs.hanko.io/passkey-api/introduction" target="_blank">docs.hanko.io</a></p>
{{end}}
</body>
</html>
Expand Down

0 comments on commit c0af643

Please sign in to comment.