From 8dffab5d3964487448f232ab4ff7a3fe46283598 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Tue, 19 Dec 2023 18:58:55 -0600 Subject: [PATCH] fix: lp lint and dev simplicities --- cmd/lotus-provider/run.go | 8 ++++++-- cmd/lotus-provider/web/hapi/simpleinfo.go | 2 +- cmd/lotus-provider/web/srv.go | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-provider/run.go b/cmd/lotus-provider/run.go index 00e3079d9..a47cb6ec4 100644 --- a/cmd/lotus-provider/run.go +++ b/cmd/lotus-provider/run.go @@ -167,12 +167,16 @@ var webCmd = &cli.Command{ cfg := config.DefaultLotusProvider() cfg.Subsystems.EnableWebGui = true var b bytes.Buffer - toml.NewEncoder(&b).Encode(cfg) + if err = toml.NewEncoder(&b).Encode(cfg); err != nil { + return err + } if err = setConfig(db, "web", b.String()); err != nil { return err } } - cctx.Set("layers", "web") + if err = cctx.Set("layers", "web"); err != nil { + return err + } return runCmd.Action(cctx) }, } diff --git a/cmd/lotus-provider/web/hapi/simpleinfo.go b/cmd/lotus-provider/web/hapi/simpleinfo.go index 470739518..a14735a84 100644 --- a/cmd/lotus-provider/web/hapi/simpleinfo.go +++ b/cmd/lotus-provider/web/hapi/simpleinfo.go @@ -77,7 +77,7 @@ func (a *app) indexTasksHistory(w http.ResponseWriter, r *http.Request) { a.executeTemplate(w, "cluster_task_history", s) } -var templateDev = os.Getenv("LOTUS_HAPI_TEMPLATE_DEV") == "1" +var templateDev = os.Getenv("LOTUS_WEB_DEV") == "1" func (a *app) executeTemplate(w http.ResponseWriter, name string, data interface{}) { if templateDev { diff --git a/cmd/lotus-provider/web/srv.go b/cmd/lotus-provider/web/srv.go index f41501fef..c618d0baa 100644 --- a/cmd/lotus-provider/web/srv.go +++ b/cmd/lotus-provider/web/srv.go @@ -6,7 +6,9 @@ import ( "embed" "net" "net/http" + "os" "strings" + "time" "github.com/gorilla/mux" "go.opencensus.io/tag" @@ -20,6 +22,10 @@ import ( // go:embed static var static embed.FS +// An dev mode hack for no-restart changes to static and templates. +// You still need to recomplie the binary for changes to go code. +var webDev = os.Getenv("LOTUS_WEB_DEV") == "1" + func GetSrv(ctx context.Context, deps *deps.Deps) (*http.Server, error) { mux := mux.NewRouter() api.Routes(mux.PathPrefix("/api").Subrouter(), deps) @@ -28,6 +34,9 @@ func GetSrv(ctx context.Context, deps *deps.Deps) (*http.Server, error) { return nil, err } mux.NotFoundHandler = http.FileServer(http.FS(static)) + if webDev { + mux.NotFoundHandler = http.FileServer(http.Dir("cmd/lotus-provider/web/static")) + } return &http.Server{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -41,6 +50,8 @@ func GetSrv(ctx context.Context, deps *deps.Deps) (*http.Server, error) { ctx, _ := tag.New(context.Background(), tag.Upsert(metrics.APIInterface, "lotus-provider")) return ctx }, - Addr: deps.Cfg.Subsystems.GuiAddress, + Addr: deps.Cfg.Subsystems.GuiAddress, + ReadTimeout: time.Minute * 3, + ReadHeaderTimeout: time.Minute * 3, // lint }, nil }