restructered some of the internals and added basic js app hooks support

This commit is contained in:
Gani Georgiev
2023-06-08 17:59:08 +03:00
parent ff5508cb79
commit 3cf3e04866
24 changed files with 1218 additions and 422 deletions
+10
View File
@@ -11,6 +11,7 @@ import (
"path/filepath"
"strings"
"github.com/dop251/goja"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"github.com/pocketbase/pocketbase/core"
@@ -34,6 +35,7 @@ func InitApi(app core.App) (*echo.Echo, error) {
e.ResetRouterCreator(func(ec *echo.Echo) echo.Router {
return echo.NewRouter(echo.RouterConfig{
UnescapePathParamValues: true,
AllowOverwritingRoute: true,
})
})
@@ -58,6 +60,14 @@ func InitApi(app core.App) (*echo.Echo, error) {
return
}
// manually extract the goja exception error value for
// consistency when throwing or returning errors
if jsException, ok := err.(*goja.Exception); ok {
if wrapped, ok := jsException.Value().Export().(error); ok {
err = wrapped
}
}
var apiErr *ApiError
switch v := err.(type) {