Files
sm-faq-plugin/routes.go
Jakub Zych 1585f06b3c feat(17-04): public FAQ API with output sanitizing, throttle bucket and README
- GET /_faq/api/v1/faqs/{slug}?locale=xx, anonymous, faq-public-api bucket (120/min per client IP)
- locale by enabled code or the default locale; active row, lowest id among duplicates
- description and answers passed through seaglass.Sanitize on output; 404 {"error":"FAQ not found"}
- TestFaqAPISmoke; README with API, CORS paths, import workflow and Winter adaptations
- go mod tidy records the test dependencies
2026-10-12 17:51:22 +02:00

22 lines
786 B
Go

package faq
import (
apicontrollers "git.golem15.com/golem15/sm-faq-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 FAQ API.
const BucketPublicAPI = "faq-public-api"
// Routes mounts the anonymous read API under /_faq/api/v1 (D-17). The group
// never attaches the backend middleware: anonymous callers would get 401.
// The slug is checked in the handler, so every miss is the JSON 404. CORS is
// the host's: it adds _faq/api/* to cors.paths.
func (p *Plugin) Routes(r pact.Router) error {
r.Group("/_faq/api/v1", surf.Use("throttle:"+BucketPublicAPI), func(g pact.Router) {
g.Get("/faqs/{slug}", apicontrollers.Show(p.app))
})
return nil
}