component/static: Seperate out static file handling

This commit is contained in:
Tom Wiesing 2022-10-06 15:41:46 +02:00
parent 3d4db1744b
commit 88a2ba4297
No known key found for this signature in database
9 changed files with 43 additions and 28 deletions

View file

@ -2,13 +2,13 @@ package control
import (
"context"
"embed"
"html/template"
"io/fs"
"net/http"
"strings"
"time"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/config"
@ -40,13 +40,6 @@ func (info *Info) Handler(route string, context context.Context, io stream.IOStr
http.NotFound(w, r)
})
// static stuff
static, err := info.disStatic()
if err != nil {
return nil, err
}
mux.Handle("/dis/static/", static)
// render everything
mux.Handle("/dis/index", httpx.HTMLHandler[disIndex]{
Handler: info.disIndex,
@ -159,18 +152,6 @@ func (info *Info) disInstance(r *http.Request) (is disInstance, err error) {
return
}
//go:embed html/static
var htmlStaticFS embed.FS
func (*Info) disStatic() (http.Handler, error) {
fs, err := fs.Sub(htmlStaticFS, "html/static")
if err != nil {
return nil, err
}
return http.StripPrefix("/dis/static/", http.FileServer(http.FS(fs))), nil
}
//go:embed "html/index.html"
var indexTemplateStr string
var indexTemplate = template.Must(template.New("index.html").Parse(indexTemplateStr))