Add DEBUG-gated panel to buy any card in the shop

When the server's DEBUG env var is on, expose a card catalog endpoint
and a collapsible client panel that drops any pet or food straight into
your deck (free, off-turn). Gated server-side so it is inert in normal
play.
This commit is contained in:
Greyson Parrelli
2026-07-23 01:07:14 -04:00
parent 71fa20493a
commit b2aa7c5ca3
13 changed files with 282 additions and 7 deletions
+15 -1
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -17,6 +18,15 @@ import (
"github.com/greyson/super-auto-pets-board-game/internal/store"
)
// isTruthy reports whether an env value means "on".
func isTruthy(v string) bool {
switch strings.ToLower(strings.TrimSpace(v)) {
case "1", "true", "yes", "on":
return true
}
return false
}
func main() {
if err := env.Load(".env"); err != nil {
slog.Error("failed to read .env", "err", err)
@@ -25,6 +35,10 @@ func main() {
dataDir := env.Get("DATA_DIR", "data")
port := env.Get("PORT", "8080")
staticDir := env.Get("STATIC_DIR", "web/dist")
debug := isTruthy(env.Get("DEBUG", ""))
if debug {
slog.Warn("DEBUG mode on: the buy-any-card panel is enabled")
}
st, err := store.Open(dataDir)
if err != nil {
@@ -40,7 +54,7 @@ func main() {
srv := &http.Server{
Addr: ":" + port,
Handler: server.New(st, staticDir).Handler(),
Handler: server.New(st, staticDir, debug).Handler(),
}
go func() {