fix: lp lint and dev simplicities

This commit is contained in:
Andrew Jackson (Ajax) 2023-12-19 18:58:55 -06:00
parent 25b228c2f6
commit 8dffab5d39
3 changed files with 19 additions and 4 deletions

View File

@ -167,12 +167,16 @@ var webCmd = &cli.Command{
cfg := config.DefaultLotusProvider() cfg := config.DefaultLotusProvider()
cfg.Subsystems.EnableWebGui = true cfg.Subsystems.EnableWebGui = true
var b bytes.Buffer 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 { if err = setConfig(db, "web", b.String()); err != nil {
return err return err
} }
} }
cctx.Set("layers", "web") if err = cctx.Set("layers", "web"); err != nil {
return err
}
return runCmd.Action(cctx) return runCmd.Action(cctx)
}, },
} }

View File

@ -77,7 +77,7 @@ func (a *app) indexTasksHistory(w http.ResponseWriter, r *http.Request) {
a.executeTemplate(w, "cluster_task_history", s) 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{}) { func (a *app) executeTemplate(w http.ResponseWriter, name string, data interface{}) {
if templateDev { if templateDev {

View File

@ -6,7 +6,9 @@ import (
"embed" "embed"
"net" "net"
"net/http" "net/http"
"os"
"strings" "strings"
"time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"go.opencensus.io/tag" "go.opencensus.io/tag"
@ -20,6 +22,10 @@ import (
// go:embed static // go:embed static
var static embed.FS 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) { func GetSrv(ctx context.Context, deps *deps.Deps) (*http.Server, error) {
mux := mux.NewRouter() mux := mux.NewRouter()
api.Routes(mux.PathPrefix("/api").Subrouter(), deps) 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 return nil, err
} }
mux.NotFoundHandler = http.FileServer(http.FS(static)) mux.NotFoundHandler = http.FileServer(http.FS(static))
if webDev {
mux.NotFoundHandler = http.FileServer(http.Dir("cmd/lotus-provider/web/static"))
}
return &http.Server{ return &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -42,5 +51,7 @@ func GetSrv(ctx context.Context, deps *deps.Deps) (*http.Server, error) {
return ctx return ctx
}, },
Addr: deps.Cfg.Subsystems.GuiAddress, Addr: deps.Cfg.Subsystems.GuiAddress,
ReadTimeout: time.Minute * 3,
ReadHeaderTimeout: time.Minute * 3, // lint
}, nil }, nil
} }