From 41ffeba1f6b14a3a0baf4631c434784a1a097e2e Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Mon, 19 Aug 2024 14:35:38 -0700 Subject: [PATCH] fix renterd cors --- nodes/hostd.go | 1 - nodes/renterd.go | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/nodes/hostd.go b/nodes/hostd.go index b3a9529..4e35656 100644 --- a/nodes/hostd.go +++ b/nodes/hostd.go @@ -214,7 +214,6 @@ func (m *Manager) StartHostd(ctx context.Context, ready chan<- struct{}) error { api.ServerWithWebhooks(wr), api.ServerWithPinnedSettings(pm), api.ServerWithExplorer(ex))) - server := http.Server{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") diff --git a/nodes/renterd.go b/nodes/renterd.go index a25f1e6..5339c89 100644 --- a/nodes/renterd.go +++ b/nodes/renterd.go @@ -164,7 +164,7 @@ func (m *Manager) StartRenterd(ctx context.Context, ready chan<- struct{}) error var workerHandler, busHandler, autopilotHandler http.Handler server := &http.Server{ - Handler: jape.BasicAuth("sia is cool")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "*") w.Header().Set("Access-Control-Allow-Headers", "*") @@ -186,7 +186,7 @@ func (m *Manager) StartRenterd(ctx context.Context, ready chan<- struct{}) error return } http.NotFound(w, r) - })), + }), ReadTimeout: 15 * time.Second, } defer server.Close() @@ -210,7 +210,7 @@ func (m *Manager) StartRenterd(ctx context.Context, ready chan<- struct{}) error log.Error("failed to shutdown bus", zap.Error(err)) } }() - busHandler = b.Handler() + busHandler = jape.BasicAuth("sia is cool")(b.Handler()) apiAddr := apiListener.Addr().String() busClient := bus.NewClient(fmt.Sprintf("http://%s/api/bus", apiAddr), "sia is cool") @@ -239,7 +239,7 @@ func (m *Manager) StartRenterd(ctx context.Context, ready chan<- struct{}) error log.Error("failed to shutdown worker", zap.Error(err)) } }() - workerHandler = w.Handler() + workerHandler = jape.BasicAuth("sia is cool")(w.Handler()) ap, err := autopilot.New(config.Autopilot{ AccountsRefillInterval: time.Second, @@ -256,7 +256,7 @@ func (m *Manager) StartRenterd(ctx context.Context, ready chan<- struct{}) error return fmt.Errorf("failed to create autopilot: %w", err) } defer ap.Shutdown(ctx) - autopilotHandler = ap.Handler() + autopilotHandler = jape.BasicAuth("sia is cool")(ap.Handler()) log.Info("node started", zap.Stringer("http", apiListener.Addr())) node.APIAddress = "http://" + apiListener.Addr().String()