static.go 570 B

12345678910111213141516171819202122
  1. // Package web contains HTTP handlers, middleware, and embedded static assets.
  2. package web
  3. import (
  4. "embed"
  5. "io/fs"
  6. "net/http"
  7. "github.com/pocketbase/pocketbase/core"
  8. )
  9. //go:embed static
  10. var staticFiles embed.FS
  11. // RegisterStatic registers the /static/* route serving embedded Bulma and htmx assets.
  12. func RegisterStatic(e *core.ServeEvent) {
  13. sub, _ := fs.Sub(staticFiles, "static")
  14. e.Router.GET("/static/{path...}", func(re *core.RequestEvent) error {
  15. http.StripPrefix("/static", http.FileServerFS(sub)).ServeHTTP(re.Response, re.Request)
  16. return nil
  17. })
  18. }