32 lines
618 B
Go
32 lines
618 B
Go
package presentation
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"code.icb4dc0.de/gophershare/gophershare/handlers/api"
|
|
)
|
|
|
|
func NewAssetsHandler(assetsFS fs.FS) (*AssetsHandler, error) {
|
|
distFS, err := fs.Sub(assetsFS, "dist")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &AssetsHandler{
|
|
FS: distFS,
|
|
}, nil
|
|
}
|
|
|
|
type AssetsHandler struct {
|
|
FS fs.FS
|
|
}
|
|
|
|
func (h AssetsHandler) Endpoints() []api.Endpoint {
|
|
return []api.Endpoint{
|
|
api.EndpointOf(func(router chi.Router) {
|
|
router.Get("/*", http.StripPrefix("/assets/", http.FileServer(http.FS(h.FS))).ServeHTTP)
|
|
}, api.AllowAnonymous()),
|
|
}
|
|
}
|