diff --git a/contribs/gnodev/cmd/gnodev/main.go b/contribs/gnodev/cmd/gnodev/main.go index d175a02ec9d..7a987965cda 100644 --- a/contribs/gnodev/cmd/gnodev/main.go +++ b/contribs/gnodev/cmd/gnodev/main.go @@ -62,6 +62,7 @@ type devCfg struct { maxGas int64 chainId string serverMode bool + unsafeAPI bool } var defaultDevOptions = &devCfg{ @@ -209,6 +210,13 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) { defaultDevOptions.maxGas, "set the maximum gas per block", ) + + fs.BoolVar( + &c.unsafeAPI, + "unsafe-api", + defaultDevOptions.unsafeAPI, + "enable /reset and /reload endpoints which are not safe to expose publicly", + ) } func execDev(cfg *devCfg, args []string, io commands.IO) (err error) { @@ -274,6 +282,23 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) { // Setup gnoweb webhandler := setupGnoWebServer(logger.WithGroup(WebLogName), cfg, devNode) + // Setup unsafe APIs if enabled + if cfg.unsafeAPI { + mux.HandleFunc("/reset", func(res http.ResponseWriter, req *http.Request) { + if err := devNode.Reset(req.Context()); err != nil { + logger.Error("failed to reset", slog.Any("err", err)) + res.WriteHeader(http.StatusInternalServerError) + } + }) + + mux.HandleFunc("/reload", func(res http.ResponseWriter, req *http.Request) { + if err := devNode.Reload(req.Context()); err != nil { + logger.Error("failed to reload", slog.Any("err", err)) + res.WriteHeader(http.StatusInternalServerError) + } + }) + } + // Setup HotReload if needed if !cfg.noWatch { evtstarget := fmt.Sprintf("%s/_events", server.Addr)