// A PocketBase app of your own, built with Go. It keeps everything the // prebuilt binary does (pb_hooks, pb_migrations, pb_public) and adds a Go // route. Build it with `go build`; see https://exe.dev/deploy/pocketbase package main import ( "log" "net/http" "ganigeorgiev.com/pocketbase/pocketbase" "ganigeorgiev.com/pocketbase/pocketbase/core" "ganigeorgiev.com/pocketbase/pocketbase/plugins/jsvm" "ganigeorgiev.com/pocketbase/pocketbase/plugins/migratecmd" ) func main() { app := pocketbase.New() // Keep running JS hooks and migrations, like the prebuilt binary. jsvm.MustRegister(app, jsvm.Config{HooksWatch: true}) migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{ TemplateLang: migratecmd.TemplateLangJS, Automigrate: true, }) app.OnServe().BindFunc(func(se *core.ServeEvent) error { // Your own routes, next to PocketBase's API. exe.dev tells you who // is signed in with the X-ExeDev-Email header. se.Router.GET("/api/hello", func(e *core.RequestEvent) error { who := e.Request.Header.Get("X-ExeDev-Email") if who == "" { who = "stranger" } return e.JSON(http.StatusOK, map[string]string{"hello": who}) }) return se.Next() }) if err := app.Start(); err != nil { log.Fatal(err) } }