From c22b57ce67a93317514d53d2f32d975fa5fb53f0 Mon Sep 17 00:00:00 2001 From: henrygd Date: Wed, 26 Feb 2025 18:42:34 -0500 Subject: [PATCH] refactor(dev): use ENV var to enable hub dev mode --- beszel/Makefile | 1 + beszel/internal/hub/hub.go | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/beszel/Makefile b/beszel/Makefile index 14048b2..53f1a99 100644 --- a/beszel/Makefile +++ b/beszel/Makefile @@ -48,6 +48,7 @@ dev-server: generate-locales cd ./site && npm run dev; \ fi +dev-hub: export ENV=dev dev-hub: mkdir -p ./site/dist && touch ./site/dist/index.html @if command -v entr >/dev/null 2>&1; then \ diff --git a/beszel/internal/hub/hub.go b/beszel/internal/hub/hub.go index b42f797..eb6df34 100644 --- a/beszel/internal/hub/hub.go +++ b/beszel/internal/hub/hub.go @@ -77,13 +77,12 @@ func GetEnv(key string) (value string, exists bool) { } func (h *Hub) Run() { - // loosely check if it was executed using "go run" - isGoRun := strings.HasPrefix(os.Args[0], os.TempDir()) + isDev := os.Getenv("ENV") == "dev" // enable auto creation of migration files when making collection changes in the Admin UI migratecmd.MustRegister(h, h.RootCmd, migratecmd.Config{ - // (the isGoRun check is to enable it only during development) - Automigrate: isGoRun, + // (the isDev check is to enable it only during development) + Automigrate: isDev, Dir: "../../migrations", }) @@ -132,7 +131,7 @@ func (h *Hub) Run() { // serve web ui h.OnServe().BindFunc(func(se *core.ServeEvent) error { - switch isGoRun { + switch isDev { case true: proxy := httputil.NewSingleHostReverseProxy(&url.URL{ Scheme: "http",