(app core.App, loader *goja.Runtime, executors *vmsPool)
| 147 | } |
| 148 | |
| 149 | func 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 | |
| 181 | func wrapHandlerFunc(executors *vmsPool, handler goja.Value) (func(*core.RequestEvent) error, error) { |
| 182 | if handler == nil { |
searching dependent graphs…