tweaked automigrate to check for git status and extracted the base flags from the plugins
This commit is contained in:
@@ -13,13 +13,11 @@ import (
|
||||
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Dir string
|
||||
IndexFallback bool
|
||||
FlagsCmd *cobra.Command
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
@@ -46,24 +44,6 @@ func Register(app core.App, options *Options) error {
|
||||
options.Dir = defaultPublicDir()
|
||||
}
|
||||
|
||||
if options.FlagsCmd != nil {
|
||||
// add "--publicDir" option flag
|
||||
options.FlagsCmd.PersistentFlags().StringVar(
|
||||
&options.Dir,
|
||||
"publicDir",
|
||||
options.Dir,
|
||||
"the directory to serve static files",
|
||||
)
|
||||
|
||||
// add "--indexFallback" option flag
|
||||
options.FlagsCmd.PersistentFlags().BoolVar(
|
||||
&options.IndexFallback,
|
||||
"indexFallback",
|
||||
options.IndexFallback,
|
||||
"fallback the request to index.html on missing static path (eg. when pretty urls are used with SPA)",
|
||||
)
|
||||
}
|
||||
|
||||
p.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
// serves static files from the provided public dir (if exists)
|
||||
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS(options.Dir), options.IndexFallback))
|
||||
@@ -79,6 +59,5 @@ func defaultPublicDir() string {
|
||||
// most likely ran with go run
|
||||
return "./pb_public"
|
||||
}
|
||||
|
||||
return filepath.Join(os.Args[0], "../pb_public")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user