Skip to content

Commit b0ec8a3

Browse files
committed
Move the init rate limit to migration file
1 parent 0afc233 commit b0ec8a3

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

cmd/web/main.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ func main() {
5353

5454
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
5555

56-
settings := app.Settings()
57-
58-
config.InitRateLimitRule(settings)
59-
60-
err := app.Save(settings)
61-
if err != nil {
62-
return err
63-
}
64-
6556
se.Router.GET("/{path...}", apis.Static(os.DirFS("./web/build"), true))
6657

6758
// 调用订阅模块,把 app, se 和 cfg 传进去
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package migrations
2+
3+
import (
4+
"website-pb/config"
5+
6+
"github.com/pocketbase/pocketbase/core"
7+
m "github.com/pocketbase/pocketbase/migrations"
8+
)
9+
10+
func init() {
11+
m.Register(func(app core.App) error {
12+
// add up queries...
13+
14+
settings := app.Settings()
15+
16+
config.InitRateLimitRule(settings)
17+
18+
err := app.Save(settings)
19+
if err != nil {
20+
return err
21+
}
22+
23+
return nil
24+
}, func(app core.App) error {
25+
// add down queries...
26+
27+
return nil
28+
})
29+
}

0 commit comments

Comments
 (0)