✨ Run PocketBase as the wotra binary
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.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user