-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
54 lines (41 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"net/http"
"os"
"pocket-react/backend"
"strings"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
_ "pocket-react/migrations"
)
func main() {
config := backend.LoadConfig()
if err := os.MkdirAll(config.DataDir, 0755); err != nil {
log.Fatal(err)
}
app := pocketbase.New()
if err := app.RootCmd.PersistentFlags().Set("dir", config.DataDir); err != nil {
log.Fatal(err)
}
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
// enable auto creation of migration files when making collection changes in the Admin UI
// (the isGoRun check is to enable it only during development)
Automigrate: isGoRun,
})
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.GET("/health", func(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{
"status": "healthy",
})
})
ServeViteAssets(e.Router)
return nil
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}