GX6008: widget route is in a group with no origins
A widget, or an action that its component invokes, is in a Group call with no gx.AllowOrigins before it.
Cause
A widget, or an action that its component invokes, is in a Group call with no gx.AllowOrigins before it. A host page has a different origin from the Gx server. The server refuses each request of a different origin to a group that lists no origins, so the widget cannot load.
Example
package cart
props {
Currency string
}
<section>
<p>Your cart in {p.Currency}</p>
</section>package route
import "github.com/alternayte/gx"
type Widget struct {
gx.Route `GET /widgets/cart`
Currency string `query:"currency" default:"EUR"`
}package cart
import (
"github.com/alternayte/gx"
"app/cart/route"
)
var CartWidget = gx.Widget(func(c *gx.Ctx, in route.Widget) (CartProps, error) {
return CartProps{Currency: in.Currency}, nil
}, Cart).Tag("acme-cart")
var Routes = gx.Collect(CartWidget)package main
import (
"net/http"
"github.com/alternayte/gx"
"app/cart"
)
func main() {
app := gx.New(gx.Config{})
app.Group("/", cart.Routes)
_ = http.ListenAndServe("127.0.0.1:8080", app)
}gx check reports:
cart/cart.go:8:18: GX6008: widget acme-cart is in a group with no gx.AllowOrigins; a page of a different origin cannot load itFix
- Put
gx.AllowOriginsbefore the routes in theGroupcall, with the origin of each host:app.Group("/", gx.AllowOrigins("https://shop.example.com"), cart.Routes). - For a widget that each site can use, write
gx.AllowOrigins(gx.AnyOrigin). - Put each action that the widget invokes in a group with origins too.