-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
49 lines (38 loc) · 1.47 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
package main
import (
"log"
"os"
"trading-statistics/eventhandlers"
_ "trading-statistics/migrations"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
)
func main() {
app := pocketbase.New()
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)",
)
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
// enable auto creation of migration files when making collection changes in the Admin UI
Automigrate: os.Getenv("AUTOMIGRATE") == "true",
})
// serves static files from the provided public dir (if exists)
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), indexFallback))
return nil
})
// app.OnRecordBeforeCreateRequest("screenshots").Add(eventhandlers.ResizeImages)
app.OnRecordBeforeCreateRequest("screenshots").Add(eventhandlers.AddImageMeta)
app.OnRecordBeforeUpdateRequest("screenshots").Add(eventhandlers.UpdateImageMeta)
app.OnRecordAfterCreateRequest("trade_log_files").Add(eventhandlers.CreateTradeRecordsFromLogFiles(app))
app.OnRecordAfterCreateRequest("trading_accounts").Add(eventhandlers.CreateDefaultPublicDashboardRecord(app))
if err := app.Start(); err != nil {
log.Fatal(err)
}
}