mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 04:40:05 +01:00
feat: adding embedded db-studio
Signed-off-by: allanice001 <allanice001@gmail.com>
This commit is contained in:
32
cmd/serve.go
32
cmd/serve.go
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/glueops/autoglue/internal/auth"
|
||||
"github.com/glueops/autoglue/internal/bg"
|
||||
"github.com/glueops/autoglue/internal/config"
|
||||
"github.com/glueops/autoglue/internal/web"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -33,6 +34,8 @@ var serveCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
var pgwebInst *web.Pgweb
|
||||
|
||||
jobs, err := bg.NewJobs(rt.DB, cfg.DbURL)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init background jobs: %v", err)
|
||||
@@ -119,7 +122,31 @@ var serveCmd = &cobra.Command{
|
||||
}
|
||||
}()
|
||||
|
||||
r := api.NewRouter(rt.DB, jobs)
|
||||
var studioHandler http.Handler
|
||||
r := api.NewRouter(rt.DB, jobs, nil)
|
||||
|
||||
if cfg.DBStudioEnabled {
|
||||
dbURL := cfg.DbURLRO
|
||||
if dbURL == "" {
|
||||
dbURL = cfg.DbURL
|
||||
}
|
||||
|
||||
pgwebInst, err = web.StartPgweb(
|
||||
dbURL,
|
||||
cfg.DBStudioBind,
|
||||
cfg.DBStudioPort,
|
||||
true,
|
||||
cfg.DBStudioUser,
|
||||
cfg.DBStudioPass,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("pgweb failed to start: %v", err)
|
||||
} else {
|
||||
studioHandler = http.HandlerFunc(pgwebInst.Proxy())
|
||||
r = api.NewRouter(rt.DB, jobs, studioHandler)
|
||||
log.Printf("pgweb running on http://%s:%s (proxied at /db-studio/)", cfg.DBStudioBind, pgwebInst.Port())
|
||||
}
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
|
||||
|
||||
@@ -143,6 +170,9 @@ var serveCmd = &cobra.Command{
|
||||
|
||||
<-ctx.Done()
|
||||
fmt.Println("\n⏳ Shutting down...")
|
||||
if pgwebInst != nil {
|
||||
_ = pgwebInst.Stop(context.Background())
|
||||
}
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
return srv.Shutdown(shutdownCtx)
|
||||
|
||||
Reference in New Issue
Block a user