From 58479668b6dd316b5b104b8118551d0edea1290d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 29 Nov 2026 17:06:46 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Run=20PocketBase=20as=20the=20wotra?= =?UTF-8?q?=20binary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The root package is now the entry point: one binary that serves the PocketBase API, applies the migrations and ships the SvelteKit build from web/build as a single-page app. The legacy chi entry point is gone. Note that the image is embedded unconditionally, so a Go build needs at least the tracked web/build/.gitkeep and a web build has to run first to get a working UI. --- main.go | 28 ++++++++++++++++++++++++++++ ui.go | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 main.go create mode 100644 ui.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..8fd4f7c --- /dev/null +++ b/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + _ "time/tzdata" + + "github.com/pocketbase/pocketbase" + "github.com/pocketbase/pocketbase/plugins/migratecmd" + "github.com/wotra/wotra/internal/legacyimport" + _ "github.com/wotra/wotra/internal/migrations" + "github.com/wotra/wotra/internal/syncapi" + "github.com/wotra/wotra/internal/tracking" +) + +func main() { + app := pocketbase.New() + + migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{Automigrate: false}) + + syncapi.Register(app) + tracking.Register(app) + legacyimport.Register(app, app.RootCmd) + registerUI(app) + + if err := app.Start(); err != nil { + log.Fatal(err) + } +} diff --git a/ui.go b/ui.go new file mode 100644 index 0000000..080a020 --- /dev/null +++ b/ui.go @@ -0,0 +1,27 @@ +package main + +import ( + "embed" + "io/fs" + "mime" + + "github.com/pocketbase/pocketbase/apis" + "github.com/pocketbase/pocketbase/core" +) + +//go:embed all:web/build +var webBuild embed.FS + +func registerUI(app core.App) { + _ = mime.AddExtensionType(".webmanifest", "application/manifest+json") + sub, err := fs.Sub(webBuild, "web/build") + if err != nil { + panic(err) + } + app.OnServe().BindFunc(func(se *core.ServeEvent) error { + if !se.Router.HasRoute("GET", "/{path...}") { + se.Router.GET("/{path...}", apis.Static(sub, true)) + } + return se.Next() + }) +}