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.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)
},
}

View File

@ -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 {

View File

@ -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
}