@@ -3,6 +3,7 @@ package api
33import (
44 "bytes"
55 "context"
6+ "errors"
67 "fmt"
78 "net/http"
89 "os"
@@ -11,6 +12,7 @@ import (
1112 "time"
1213
1314 "github.com/safing/portbase/info"
15+ "github.com/safing/portbase/modules"
1416 "github.com/safing/portbase/utils/debug"
1517)
1618
@@ -25,6 +27,16 @@ func registerDebugEndpoints() error {
2527 return err
2628 }
2729
30+ if err := RegisterEndpoint (Endpoint {
31+ Path : "ready" ,
32+ Read : PermitAnyone ,
33+ ActionFunc : ready ,
34+ Name : "Ready" ,
35+ Description : "Check if Portmaster has completed starting and is ready." ,
36+ }); err != nil {
37+ return err
38+ }
39+
2840 if err := RegisterEndpoint (Endpoint {
2941 Path : "debug/stack" ,
3042 Read : PermitAnyone ,
@@ -118,9 +130,22 @@ You can easily view this data in your browser with this command (with Go install
118130
119131// ping responds with pong.
120132func ping (ar * Request ) (msg string , err error ) {
133+ // TODO: Remove upgrade to "ready" when all UI components have transitioned.
134+ if modules .IsStarting () || modules .IsShuttingDown () {
135+ return "" , ErrorWithStatus (errors .New ("portmaster is not ready, reload (F5) to try again" ), http .StatusTooEarly )
136+ }
137+
121138 return "Pong." , nil
122139}
123140
141+ // ready checks if Portmaster has completed starting.
142+ func ready (ar * Request ) (msg string , err error ) {
143+ if modules .IsStarting () || modules .IsShuttingDown () {
144+ return "" , ErrorWithStatus (errors .New ("portmaster is not ready, reload (F5) to try again" ), http .StatusTooEarly )
145+ }
146+ return "Portmaster is ready." , nil
147+ }
148+
124149// getStack returns the current goroutine stack.
125150func getStack (_ * Request ) (data []byte , err error ) {
126151 buf := & bytes.Buffer {}
0 commit comments