@@ -3,6 +3,7 @@ package api
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "errors"
6
7
"fmt"
7
8
"net/http"
8
9
"os"
@@ -11,6 +12,7 @@ import (
11
12
"time"
12
13
13
14
"github.com/safing/portbase/info"
15
+ "github.com/safing/portbase/modules"
14
16
"github.com/safing/portbase/utils/debug"
15
17
)
16
18
@@ -25,6 +27,16 @@ func registerDebugEndpoints() error {
25
27
return err
26
28
}
27
29
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
+
28
40
if err := RegisterEndpoint (Endpoint {
29
41
Path : "debug/stack" ,
30
42
Read : PermitAnyone ,
@@ -118,9 +130,22 @@ You can easily view this data in your browser with this command (with Go install
118
130
119
131
// ping responds with pong.
120
132
func 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
+
121
138
return "Pong." , nil
122
139
}
123
140
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
+
124
149
// getStack returns the current goroutine stack.
125
150
func getStack (_ * Request ) (data []byte , err error ) {
126
151
buf := & bytes.Buffer {}
0 commit comments