Refactor server and templates package

This commit is contained in:
Tom Wiesing 2023-01-19 13:22:48 +01:00
parent b6bf0a8900
commit 6ede99d7c6
No known key found for this signature in database
105 changed files with 341 additions and 339 deletions

View file

@ -0,0 +1,41 @@
// Package static implements serving of fully static resources
package assets
import (
"context"
"embed"
"io/fs"
"net/http"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
)
type Static struct {
component.Base
}
var (
_ component.Routeable = (*Static)(nil)
)
func (*Static) Routes() component.Routes {
return component.Routes{
Prefix: Public,
CSRF: false,
}
}
//go:embed dist
var staticFS embed.FS
func (static *Static) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
// take the filesystem
fs, err := fs.Sub(staticFS, "dist")
if err != nil {
return nil, err
}
// and serve it
return http.StripPrefix(route, http.FileServer(http.FS(fs))), nil
}