Add IRI to local resources (#1046)
* initial commit * add remote trail/list * fix errors * update to use new IRIs * use origin in migration instead * use UnsafeWithoutHooks * fix trail/list order of operations * fix remote trail/list fetch * fixes list document update * fix errors --------- Co-authored-by: Christian Beutel <>
This commit is contained in:
28
db/hooks/waypoint.go
Normal file
28
db/hooks/waypoint.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func CreateWaypointHandler() func(e *core.RecordRequestEvent) error {
|
||||
return func(e *core.RecordRequestEvent) error {
|
||||
err := e.Next()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add local iri
|
||||
origin := os.Getenv("ORIGIN")
|
||||
if origin == "" {
|
||||
return fmt.Errorf("ORIGIN not set")
|
||||
}
|
||||
if e.Record.GetString("iri") == "" {
|
||||
e.Record.Set("iri", fmt.Sprintf("%s/api/v1/waypoint/%s", origin, e.Record.Id))
|
||||
}
|
||||
|
||||
return e.App.UnsafeWithoutHooks().Save(e.Record)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user