Refactor server and templates package
This commit is contained in:
parent
b6bf0a8900
commit
6ede99d7c6
105 changed files with 341 additions and 339 deletions
41
internal/dis/component/server/assets/static.go
Normal file
41
internal/dis/component/server/assets/static.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue