+6
-2
appview/state/state.go
+6
-2
appview/state/state.go
···
122
122
log.Println("has secret ", secret)
123
123
124
124
// make a request do the knotserver with an empty body and above signature
125
-
url := fmt.Sprintf("http://%s/internal/health", domain)
125
+
url := fmt.Sprintf("http://%s/health", domain)
126
126
127
127
pingRequest, err := buildPingRequest(url, secret)
128
128
if err != nil {
···
164
164
w.Write([]byte("check success"))
165
165
166
166
// mark as registered
167
-
s.Db.Register(domain)
167
+
err = s.Db.Register(domain)
168
+
if err != nil {
169
+
log.Println("failed to register domain", err)
170
+
http.Error(w, err.Error(), http.StatusInternalServerError)
171
+
}
168
172
169
173
return
170
174
}
+5
-7
knotserver/handler.go
+5
-7
knotserver/handler.go
···
17
17
db: db,
18
18
}
19
19
20
-
r.Route("/settings", func(r chi.Router) {
21
-
r.Get("/keys", h.Keys)
22
-
r.Put("/keys", h.Keys)
23
-
})
24
-
25
20
r.Get("/", h.Index)
26
21
r.Route("/{did}", func(r chi.Router) {
27
22
// Repo routes
···
49
44
r.Put("/new", h.NewRepo)
50
45
})
51
46
52
-
r.Route("/internal", func(r chi.Router) {
47
+
r.With(h.VerifySignature).Get("/health", h.Health)
48
+
49
+
r.Group(func(r chi.Router) {
53
50
r.Use(h.VerifySignature)
54
-
r.Get("/health", h.Health)
51
+
r.Get("/keys", h.Keys)
52
+
r.Put("/keys", h.Keys)
55
53
})
56
54
57
55
return r, nil
+1
-1
knotserver/routes.go
+1
-1
knotserver/routes.go
···
393
393
394
394
func (h *Handle) Health(w http.ResponseWriter, r *http.Request) {
395
395
log.Println("got health check")
396
-
mac := hmac.New(sha256.New, []byte(h.c.Secret))
396
+
mac := hmac.New(sha256.New, []byte(h.c.Server.Secret))
397
397
mac.Write([]byte("ok"))
398
398
w.Header().Add("X-Signature", hex.EncodeToString(mac.Sum(nil)))
399
399