From 95e965d5dfd12b3bdeeeaa6278f04f2c9ee08945 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Fri, 21 Feb 2025 19:32:23 +0100 Subject: [PATCH] Return 503 ServiceUnavailable from public interface if not synced --- server/public.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/public.go b/server/public.go index 6ec9fb1a..84ba710b 100644 --- a/server/public.go +++ b/server/public.go @@ -59,6 +59,7 @@ type PublicServer struct { is *common.InternalState fiatRates *fiat.FiatRates useSatsAmountFormat bool + isFullInterface bool } // NewPublicServer creates new public server http interface to blockbook and returns its handle @@ -216,6 +217,7 @@ func (s *PublicServer) ConnectFullPublicInterface() { serveMux.Handle(path+"socket.io/", s.socketio.GetHandler()) // websocket interface serveMux.Handle(path+"websocket", s.websocket.GetHandler()) + s.isFullInterface = true } // Close closes the server @@ -998,6 +1000,11 @@ func (s *PublicServer) explorerBlock(w http.ResponseWriter, r *http.Request) (tp } func (s *PublicServer) explorerIndex(w http.ResponseWriter, r *http.Request) (tpl, *TemplateData, error) { + if !s.isFullInterface && r.URL.Path != "/" { + w.WriteHeader(http.StatusServiceUnavailable) + w.Write([]byte("Service unavailable")) + return noTpl, nil, nil + } var si *api.SystemInfo var err error s.metrics.ExplorerViews.With(common.Labels{"action": "index"}).Inc() @@ -1142,6 +1149,9 @@ func getPagingRange(page int, total int) ([]int, int, int) { } func (s *PublicServer) apiIndex(r *http.Request, apiVersion int) (interface{}, error) { + if !s.isFullInterface && r.URL.Path != "/api/" { + return nil, api.NewAPIError("Service unavailable", false) + } s.metrics.ExplorerViews.With(common.Labels{"action": "api-index"}).Inc() return s.api.GetSystemInfo(false) }