mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-24 23:31:54 +02:00
updated comments and pass the dashboard path into the installer
This commit is contained in:
parent
e4cd6810ab
commit
bed45beb13
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@ -16,9 +17,8 @@ import (
|
|||||||
"github.com/pocketbase/pocketbase/tools/security"
|
"github.com/pocketbase/pocketbase/tools/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
const installerHookId = "__pbinstallerHook"
|
// @todo consider combining with the installer specific hooks after refactoring cmd
|
||||||
|
func loadInstaller(app core.App, dashboardURL string) error {
|
||||||
func loadInstaller(app core.App, hostURL string) error {
|
|
||||||
if !needInstallerSuperuser(app) {
|
if !needInstallerSuperuser(app) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -34,11 +34,11 @@ func loadInstaller(app core.App, hostURL string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// launch url (ignore errors and always print a help text as fallback)
|
// launch url (ignore errors and always print a help text as fallback)
|
||||||
url := fmt.Sprintf("%s/_/#/pbinstal/%s", hostURL, token)
|
url := fmt.Sprintf("%s/#/pbinstal/%s", strings.TrimRight(dashboardURL, "/"), token)
|
||||||
_ = launchURL(url)
|
_ = launchURL(url)
|
||||||
color.Magenta("\n(!) Launch the URL below in the browser if it hasn't been open already to create your first superuser account:")
|
color.Magenta("\n(!) Launch the URL below in the browser if it hasn't been open already to create your first superuser account:")
|
||||||
color.New(color.Bold).Add(color.FgCyan).Println(url)
|
color.New(color.Bold).Add(color.FgCyan).Println(url)
|
||||||
color.New(color.FgHiBlack, color.Italic).Printf("(you can also create your first superuser account by running '%s superuser upsert test@example.com yourpass' and restart the server)\n", os.Args[0])
|
color.New(color.FgHiBlack, color.Italic).Printf("(you can also create your first superuser account by running '%s superuser upsert test@example.com yourpass')\n", os.Args[0])
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -47,6 +47,7 @@ func needInstallerSuperuser(app core.App) bool {
|
|||||||
total, err := app.CountRecords(core.CollectionNameSuperusers, dbx.Not(dbx.HashExp{
|
total, err := app.CountRecords(core.CollectionNameSuperusers, dbx.Not(dbx.HashExp{
|
||||||
"email": core.DefaultInstallerEmail,
|
"email": core.DefaultInstallerEmail,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return err == nil && total == 0
|
return err == nil && total == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,9 @@ type ServeConfig struct {
|
|||||||
// ShowStartBanner indicates whether to show or hide the server start console message.
|
// ShowStartBanner indicates whether to show or hide the server start console message.
|
||||||
ShowStartBanner bool
|
ShowStartBanner bool
|
||||||
|
|
||||||
// DashboardPath specifies the route path to the superusers dashboard interface
|
// DashboardPath specifies the route path to the superusers dashboard (default to "_").
|
||||||
// (default to "/_/{path...}").
|
|
||||||
//
|
//
|
||||||
// Note: Must include the "{path...}" wildcard parameter.
|
// Currently it is limited to a single path segment (this is because the UI is not extendable at the moment).
|
||||||
DashboardPath string
|
DashboardPath string
|
||||||
|
|
||||||
// HttpAddr is the TCP address to listen for the HTTP server (eg. "127.0.0.1:80").
|
// HttpAddr is the TCP address to listen for the HTTP server (eg. "127.0.0.1:80").
|
||||||
@ -68,9 +67,12 @@ func Serve(app core.App, config ServeConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.DashboardPath == "" {
|
if config.DashboardPath == "" {
|
||||||
config.DashboardPath = "/_/{path...}"
|
config.DashboardPath = "_"
|
||||||
} else if !strings.HasSuffix(config.DashboardPath, "{path...}") {
|
} else {
|
||||||
return errors.New("invalid dashboard path - missing {path...} wildcard")
|
config.DashboardPath = strings.Trim(config.DashboardPath, "/")
|
||||||
|
if strings.Contains(config.DashboardPath, "/") {
|
||||||
|
return errors.New("the dashboard path must be single path segment: _, admin, etc.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that the latest migrations are applied before starting the server
|
// ensure that the latest migrations are applied before starting the server
|
||||||
@ -89,7 +91,7 @@ func Serve(app core.App, config ServeConfig) error {
|
|||||||
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
|
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
pbRouter.GET(config.DashboardPath, Static(ui.DistDirFS, false)).
|
pbRouter.GET("/"+config.DashboardPath+"/{path...}", Static(ui.DistDirFS, false)).
|
||||||
BindFunc(func(e *core.RequestEvent) error {
|
BindFunc(func(e *core.RequestEvent) error {
|
||||||
// ingore root path
|
// ingore root path
|
||||||
if e.Request.PathValue(StaticWildcardParam) != "" {
|
if e.Request.PathValue(StaticWildcardParam) != "" {
|
||||||
@ -252,7 +254,8 @@ func Serve(app core.App, config ServeConfig) error {
|
|||||||
addr = config.CertificateDomains[0]
|
addr = config.CertificateDomains[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fullAddr := fmt.Sprintf("%s://%s", schema, addr)
|
baseURL := fmt.Sprintf("%s://%s", schema, addr)
|
||||||
|
dashboardURL := fmt.Sprintf("%s/%s", baseURL, config.DashboardPath)
|
||||||
|
|
||||||
if config.ShowStartBanner {
|
if config.ShowStartBanner {
|
||||||
date := new(strings.Builder)
|
date := new(strings.Builder)
|
||||||
@ -262,16 +265,16 @@ func Serve(app core.App, config ServeConfig) error {
|
|||||||
bold.Printf(
|
bold.Printf(
|
||||||
"%s Server started at %s\n",
|
"%s Server started at %s\n",
|
||||||
strings.TrimSpace(date.String()),
|
strings.TrimSpace(date.String()),
|
||||||
color.CyanString("%s", fullAddr),
|
color.CyanString("%s", baseURL),
|
||||||
)
|
)
|
||||||
|
|
||||||
regular := color.New()
|
regular := color.New()
|
||||||
regular.Printf("├─ REST API: %s\n", color.CyanString("%s/api/", fullAddr))
|
regular.Printf("├─ REST API: %s\n", color.CyanString("%s/api/", baseURL))
|
||||||
regular.Printf("└─ Dashboard: %s\n", color.CyanString("%s/_/", fullAddr))
|
regular.Printf("└─ Dashboard: %s\n", color.CyanString("%s/", dashboardURL))
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
installerErr := loadInstaller(app, fullAddr)
|
installerErr := loadInstaller(app, dashboardURL)
|
||||||
if installerErr != nil {
|
if installerErr != nil {
|
||||||
app.Logger().Warn("Failed to initialize installer", "error", installerErr)
|
app.Logger().Warn("Failed to initialize installer", "error", installerErr)
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
|
|||||||
command.PersistentFlags().StringVar(
|
command.PersistentFlags().StringVar(
|
||||||
&dashboardPath,
|
&dashboardPath,
|
||||||
"dashboard",
|
"dashboard",
|
||||||
"/_/{path...}",
|
"_",
|
||||||
"The route path to the superusers dashboard; must include the '{path...}' wildcard parameter",
|
"The route path to the superusers dashboard (currently limited to a single path segment)",
|
||||||
)
|
)
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewSuperuserCommand creates and returns new command for managing
|
// NewSuperuserCommand creates and returns new command for managing
|
||||||
// superuser accounts (create, update, delete).
|
// superuser accounts (create, update, upsert, delete).
|
||||||
func NewSuperuserCommand(app core.App) *cobra.Command {
|
func NewSuperuserCommand(app core.App) *cobra.Command {
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Use: "superuser",
|
Use: "superuser",
|
||||||
|
@ -141,7 +141,7 @@ func NewWithConfig(config Config) *PocketBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the application, aka. registers the default system
|
// Start starts the application, aka. registers the default system
|
||||||
// commands (serve, migrate, version) and executes pb.RootCmd.
|
// commands (serve, superuser, version) and executes pb.RootCmd.
|
||||||
func (pb *PocketBase) Start() error {
|
func (pb *PocketBase) Start() error {
|
||||||
// register system commands
|
// register system commands
|
||||||
pb.RootCmd.AddCommand(cmd.NewSuperuserCommand(pb))
|
pb.RootCmd.AddCommand(cmd.NewSuperuserCommand(pb))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user