MCPcopy
hub / github.com/pocketbase/pocketbase / routerBinds

Function routerBinds

plugins/jsvm/binds.go:149–179  ·  view source on GitHub ↗
(app core.App, loader *goja.Runtime, executors *vmsPool)

Source from the content-addressed store, hash-verified

147}
148
149func routerBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
150 loader.Set("routerAdd", func(method string, path string, handler goja.Value, middlewares ...goja.Value) {
151 wrappedMiddlewares, err := wrapMiddlewares(executors, middlewares...)
152 if err != nil {
153 panic("[routerAdd] failed to wrap middlewares: " + err.Error())
154 }
155
156 wrappedHandler, err := wrapHandlerFunc(executors, handler)
157 if err != nil {
158 panic("[routerAdd] failed to wrap handler: " + err.Error())
159 }
160
161 app.OnServe().BindFunc(func(e *core.ServeEvent) error {
162 e.Router.Route(strings.ToUpper(method), path, wrappedHandler).Bind(wrappedMiddlewares...)
163
164 return e.Next()
165 })
166 })
167
168 loader.Set("routerUse", func(middlewares ...goja.Value) {
169 wrappedMiddlewares, err := wrapMiddlewares(executors, middlewares...)
170 if err != nil {
171 panic("[routerUse] failed to wrap middlewares: " + err.Error())
172 }
173
174 app.OnServe().BindFunc(func(e *core.ServeEvent) error {
175 e.Router.Bind(wrappedMiddlewares...)
176 return e.Next()
177 })
178 })
179}
180
181func wrapHandlerFunc(executors *vmsPool, handler goja.Value) (func(*core.RequestEvent) error, error) {
182 if handler == nil {

Callers 3

TestRouterBindsCountFunction · 0.85
TestRouterBindsFunction · 0.85
registerHooksMethod · 0.85

Calls 9

wrapMiddlewaresFunction · 0.85
wrapHandlerFuncFunction · 0.85
RouteMethod · 0.80
SetMethod · 0.65
ErrorMethod · 0.65
OnServeMethod · 0.65
NextMethod · 0.65
BindFuncMethod · 0.45
BindMethod · 0.45

Tested by 2

TestRouterBindsCountFunction · 0.68
TestRouterBindsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…