Skip to content
Gx
GitHub

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

cart/Cart.gx
package cart

props {
  Currency string
}

<section>
  <p>Your cart in {p.Currency}</p>
</section>
cart/route/route.go
package route

import "github.com/alternayte/gx"

type Widget struct {
	gx.Route `GET /widgets/cart`
	Currency string `query:"currency" default:"EUR"`
}
cart/cart.go
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)
main.go
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:

gx check
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 it

Fix

  1. Put gx.AllowOrigins before the routes in the Group call, with the origin of each host: app.Group("/", gx.AllowOrigins("https://shop.example.com"), cart.Routes).
  2. For a widget that each site can use, write gx.AllowOrigins(gx.AnyOrigin).
  3. Put each action that the widget invokes in a group with origins too.