NewRouter returns a new router instance loaded with the default app middlewares and routes.
(app core.App)
| 17 | |
| 18 | // NewRouter returns a new router instance loaded with the default app middlewares and routes. |
| 19 | func NewRouter(app core.App) (*router.Router[*core.RequestEvent], error) { |
| 20 | pbRouter := router.NewRouter(func(w http.ResponseWriter, r *http.Request) (*core.RequestEvent, router.EventCleanupFunc) { |
| 21 | event := new(core.RequestEvent) |
| 22 | event.Response = w |
| 23 | event.Request = r |
| 24 | event.App = app |
| 25 | |
| 26 | return event, nil |
| 27 | }) |
| 28 | |
| 29 | // register default middlewares |
| 30 | pbRouter.Bind(activityLogger()) |
| 31 | pbRouter.Bind(panicRecover()) |
| 32 | pbRouter.Bind(rateLimit()) |
| 33 | pbRouter.Bind(loadAuthToken()) |
| 34 | pbRouter.Bind(superuserIPsWhitelist()) |
| 35 | pbRouter.Bind(securityHeaders()) |
| 36 | pbRouter.Bind(BodyLimit(DefaultMaxBodySize)) |
| 37 | |
| 38 | // API routes |
| 39 | apiGroup := pbRouter.Group("/api") |
| 40 | bindSettingsApi(app, apiGroup) |
| 41 | bindCollectionApi(app, apiGroup) |
| 42 | bindRecordCrudApi(app, apiGroup) |
| 43 | bindRecordAuthApi(app, apiGroup) |
| 44 | bindLogsApi(app, apiGroup) |
| 45 | bindBackupApi(app, apiGroup) |
| 46 | bindCronApi(app, apiGroup) |
| 47 | bindFileApi(app, apiGroup) |
| 48 | bindBatchApi(app, apiGroup) |
| 49 | bindRealtimeApi(app, apiGroup) |
| 50 | bindHealthApi(app, apiGroup) |
| 51 | bindSQLApi(app, apiGroup) |
| 52 | |
| 53 | // UI routes |
| 54 | bindUIExtensions(app) |
| 55 | |
| 56 | return pbRouter, nil |
| 57 | } |
| 58 | |
| 59 | // WrapStdHandler wraps Go [http.Handler] into a PocketBase handler func. |
| 60 | func WrapStdHandler(h http.Handler) func(*core.RequestEvent) error { |
searching dependent graphs…