Files
sm-menu-plugin/routes.go
Jakub Zych 33a65ad802 feat(17-04): public menu API with registry resolution, throttle bucket and README
- GET /_menu/api/v1/menus/{code}?locale=xx, anonymous, menu-public-api bucket (120/min per client IP)
- classes.BuildTree: published entries nested by parent, sort_order then id, scheme-checked URLs
- registry entries resolved through signpost with url_pattern as the item override and the locale's alternate
- list types keep stored URL and title, generated children follow stored ones; unresolvable entries left out
- TestMenuAPISmoke; README with API, CORS paths, import workflow and Winter adaptations
- go mod tidy records the test dependencies
2026-10-12 17:51:27 +02:00

22 lines
799 B
Go

package menu
import (
apicontrollers "git.golem15.com/golem15/sm-menu-plugin/controllers/api"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/surf"
)
// BucketPublicAPI is the throttle bucket of the public menu API.
const BucketPublicAPI = "menu-public-api"
// Routes mounts the anonymous read API under /_menu/api/v1 (D-16). The group
// never attaches the backend middleware: anonymous callers would get 401.
// The menu code is checked in the handler, so every miss is the JSON 404.
// CORS is the host's: it adds _menu/api/* to cors.paths.
func (p *Plugin) Routes(r pact.Router) error {
r.Group("/_menu/api/v1", surf.Use("throttle:"+BucketPublicAPI), func(g pact.Router) {
g.Get("/menus/{code}", apicontrollers.Show(p.app))
})
return nil
}