mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-02-13 08:24:37 +02:00
80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/pocketbase/pocketbase"
|
|
"github.com/pocketbase/pocketbase/plugins/jsvm"
|
|
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
|
"github.com/pocketbase/pocketbase/plugins/publicdir"
|
|
)
|
|
|
|
func main() {
|
|
app := pocketbase.New()
|
|
|
|
// ---------------------------------------------------------------
|
|
// Optional plugin flags:
|
|
// ---------------------------------------------------------------
|
|
|
|
var migrationsDir string
|
|
app.RootCmd.PersistentFlags().StringVar(
|
|
&migrationsDir,
|
|
"migrationsDir",
|
|
"",
|
|
"the directory with the user defined migrations",
|
|
)
|
|
|
|
var automigrate bool
|
|
app.RootCmd.PersistentFlags().BoolVar(
|
|
&automigrate,
|
|
"automigrate",
|
|
true,
|
|
"enable/disable auto migrations",
|
|
)
|
|
|
|
var publicDir string
|
|
app.RootCmd.PersistentFlags().StringVar(
|
|
&publicDir,
|
|
"publicDir",
|
|
"",
|
|
"the directory to serve static files",
|
|
)
|
|
|
|
var indexFallback bool
|
|
app.RootCmd.PersistentFlags().BoolVar(
|
|
&indexFallback,
|
|
"indexFallback",
|
|
true,
|
|
"fallback the request to index.html on missing static path (eg. when pretty urls are used with SPA)",
|
|
)
|
|
|
|
app.RootCmd.ParseFlags(os.Args[1:])
|
|
|
|
// ---------------------------------------------------------------
|
|
// Plugins:
|
|
// ---------------------------------------------------------------
|
|
|
|
// load js pb_migrations
|
|
jsvm.MustRegisterMigrationsLoader(app, &jsvm.MigrationsLoaderOptions{
|
|
Dir: migrationsDir,
|
|
})
|
|
|
|
// migrate command (with js templates)
|
|
migratecmd.MustRegister(app, app.RootCmd, &migratecmd.Options{
|
|
TemplateLang: migratecmd.TemplateLangJS,
|
|
Automigrate: automigrate,
|
|
Dir: migrationsDir,
|
|
})
|
|
|
|
// pb_public dir
|
|
publicdir.MustRegister(app, &publicdir.Options{
|
|
Dir: publicDir,
|
|
IndexFallback: indexFallback,
|
|
})
|
|
|
|
if err := app.Start(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|